diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2015-07-31 20:47:09 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2015-07-31 20:47:09 -0700 |
commit | f6a7f695c06cbc0a41069e7ef08e9926c3bb3116 (patch) | |
tree | b0c38e09a80cfa2149022e0bc16ca5d9751a8bd4 /src/base/cba | |
parent | bab71101ec16852f1fbefdf5183a8e6300233323 (diff) | |
download | abc-f6a7f695c06cbc0a41069e7ef08e9926c3bb3116.tar.gz abc-f6a7f695c06cbc0a41069e7ef08e9926c3bb3116.tar.bz2 abc-f6a7f695c06cbc0a41069e7ef08e9926c3bb3116.zip |
Improvements to Cba data-structure.
Diffstat (limited to 'src/base/cba')
-rw-r--r-- | src/base/cba/cba.c | 4 | ||||
-rw-r--r-- | src/base/cba/cba.h | 94 | ||||
-rw-r--r-- | src/base/cba/cbaBlast.c | 36 | ||||
-rw-r--r-- | src/base/cba/cbaCba.c | 16 | ||||
-rw-r--r-- | src/base/cba/cbaCom.c | 156 | ||||
-rw-r--r-- | src/base/cba/cbaNtk.c | 8 | ||||
-rw-r--r-- | src/base/cba/cbaPrs.h | 19 | ||||
-rw-r--r-- | src/base/cba/cbaReadBlif.c | 202 | ||||
-rw-r--r-- | src/base/cba/cbaReadVer.c | 26 | ||||
-rw-r--r-- | src/base/cba/cbaWriteBlif.c | 82 | ||||
-rw-r--r-- | src/base/cba/cbaWriteVer.c | 434 |
11 files changed, 813 insertions, 264 deletions
diff --git a/src/base/cba/cba.c b/src/base/cba/cba.c index 87a5b5cd..e825f052 100644 --- a/src/base/cba/cba.c +++ b/src/base/cba/cba.c @@ -4,9 +4,9 @@ SystemName [ABC: Logic synthesis and verification system.] - PackageName [Verilog parser.] + PackageName [Hierarchical word-level netlist.] - Synopsis [Parses several flavors of word-level Verilog.] + Synopsis [] Author [Alan Mishchenko] diff --git a/src/base/cba/cba.h b/src/base/cba/cba.h index 351c0b6e..cf95204f 100644 --- a/src/base/cba/cba.h +++ b/src/base/cba/cba.h @@ -47,7 +47,8 @@ typedef enum { CBA_OBJ_BOX, // 3: box CBA_BOX_SLICE, - CBA_BOX_CONCAT, + CBA_BOX_CATIN, + CBA_BOX_CATOUT, CBA_BOX_CF, CBA_BOX_CT, @@ -112,8 +113,9 @@ typedef enum { CBA_BOX_ROTL, CBA_BOX_ROTR, - CBA_BOX_GATE, + CBA_BOX_NODE, CBA_BOX_LUT, + CBA_BOX_GATE, CBA_BOX_ASSIGN, CBA_BOX_TRI, @@ -188,11 +190,16 @@ struct Cba_Man_t_ Abc_Nam_t * pStrs; // string manager Abc_Nam_t * pCons; // constant manager Abc_Nam_t * pMods; // module name manager + Vec_Int_t vNameMap; // mapping names + Vec_Int_t vNameMap2;// mapping names + Vec_Int_t vUsed; // used map entries + Vec_Int_t vUsed2; // used map entries char * pTypeNames[CBA_BOX_LAST]; // internal data int iRoot; // root network Vec_Ptr_t vNtks; // networks // user data + int nOpens; Vec_Str_t vOut; Vec_Str_t vOut2; void * pMioLib; @@ -230,6 +237,7 @@ static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { r static inline int Cba_NtkStrId( Cba_Ntk_t * p, char * pName ) { return Cba_ManStrId(p->pDesign, pName); } static inline int Cba_NtkNewStrId( Cba_Ntk_t * p, char * pName ) { return Cba_ManNewStrId(p->pDesign, pName); } static inline char * Cba_NtkConst( Cba_Ntk_t * p, int i ) { return Cba_ManConst(p->pDesign, i); } +static inline char * Cba_NtkSop( Cba_Ntk_t * p, int i ) { return Cba_ManConst(p->pDesign, i); } static inline int Cba_NtkNameId( Cba_Ntk_t * p ) { return p->NameId; } static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return Cba_NtkStr(p, p->NameId); } static inline char * Cba_NtkTypeName( Cba_Ntk_t * p, int Type ) { return p->pDesign->pTypeNames[Type]; } @@ -301,7 +309,7 @@ static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { a static inline void Cba_ObjCleanType( Cba_Ntk_t * p, int i ) { assert(i>0); Vec_StrWriteEntry( &p->vObjType, i, (char)CBA_OBJ_NONE ); } static inline int Cba_TypeIsBox( Cba_ObjType_t Type ) { return Type >= CBA_OBJ_BOX && Type < CBA_BOX_LAST; } static inline int Cba_TypeIsSeq( Cba_ObjType_t Type ) { return Type >= CBA_BOX_RAM && Type <= CBA_BOX_DFFRS; } -static inline int Cba_TypeIsUnary( Cba_ObjType_t Type ) { return Type == CBA_BOX_BUF || Type == CBA_BOX_INV || Type == CBA_BOX_LNOT || Type == CBA_BOX_MIN || (Type >= CBA_BOX_RAND && Type <= CBA_BOX_RXNOR); } +static inline int Cba_TypeIsUnary( Cba_ObjType_t Type ) { return Type == CBA_BOX_BUF || Type == CBA_BOX_INV || Type == CBA_BOX_LNOT || Type == CBA_BOX_MIN || Type == CBA_BOX_ABS || (Type >= CBA_BOX_RAND && Type <= CBA_BOX_RXNOR); } static inline int Cba_TypeIsMux( Cba_ObjType_t Type ) { return Type == CBA_BOX_MUX || Type == CBA_BOX_NMUX || Type == CBA_BOX_SEL || Type == CBA_BOX_PSEL; } static inline int Cba_ObjIsPi( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PI; } @@ -312,7 +320,8 @@ static inline int Cba_ObjIsBoxUser( Cba_Ntk_t * p, int i ) { r static inline int Cba_ObjIsBoxPrim( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) > CBA_OBJ_BOX && Cba_ObjType(p, i) < CBA_BOX_LAST; } static inline int Cba_ObjIsGate( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_GATE; } static inline int Cba_ObjIsSlice( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_SLICE; } -static inline int Cba_ObjIsConcat( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_CONCAT; } +static inline int Cba_ObjIsCatIn( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_CATIN; } +static inline int Cba_ObjIsCatOut( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_CATOUT; } static inline int Cba_ObjIsUnary( Cba_Ntk_t * p, int i ) { return Cba_TypeIsUnary(Cba_ObjType(p, i)); } static inline int Cba_ObjFin0( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntry(&p->vObjFin0, i); } @@ -354,11 +363,12 @@ static inline int Cba_FonIsReal( int f ) { r static inline int Cba_FonIsConst( int f ) { return f < 0; } static inline int Cba_FonConst( int f ) { assert(Cba_FonIsConst(f)); return -f-1; } static inline int Cba_FonFromConst( int c ) { assert(c >= 0); return -c-1; } +static inline int Cba_FonConstRange( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsConst(f)); return atoi(Cba_NtkConst(p, Cba_FonConst(f))); } static inline int Cba_FonObj( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry(&p->vFonObj, f) : 0; } static inline int Cba_FonLeft( Cba_Ntk_t * p, int f ) { return Cba_NtkHasFonLefts(p) ? Vec_IntEntry(&p->vFonLeft, f) : 0; } static inline int Cba_FonRight( Cba_Ntk_t * p, int f ) { return Cba_NtkHasFonRights(p) ? Vec_IntEntry(&p->vFonRight, f) : 0; } -static inline int Cba_FonRange( Cba_Ntk_t * p, int f ) { int l = Cba_FonLeft(p, f), r = Cba_FonRight(p, f); return 1 + (l > r ? l-r : r-l); } +static inline int Cba_FonRange( Cba_Ntk_t * p, int f ) { int l, r; if (Cba_FonIsConst(f)) return Cba_FonConstRange(p, f); l = Cba_FonLeft(p, f), r = Cba_FonRight(p, f); return 1 + (l > r ? l-r : r-l); } static inline void Cba_FonSetLeft( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonLefts(p)); Vec_IntSetEntry(&p->vFonLeft, f, x); } static inline void Cba_FonSetRight( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonRights(p)); Vec_IntSetEntry(&p->vFonRight, f, x); } static inline int Cba_FonCopy( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry(&p->vFonCopy, f) : f; } @@ -791,7 +801,8 @@ static inline Cba_Man_t * Cba_ManAlloc( char * pFileName, int nNtks, Abc_Nam_t * Abc_NamStrFindOrAdd(pNew->pCons, "1\'bz", NULL); } Vec_PtrGrow( &pNew->vNtks, nNtks+1 ); Vec_PtrPush( &pNew->vNtks, NULL ); - if ( nNtks == 1 ) pNew->iRoot = 1; + // set default root module + pNew->iRoot = 1; return pNew; } static inline void Cba_ManDupTypeNames( Cba_Man_t * pNew, Cba_Man_t * p ) @@ -830,12 +841,58 @@ static inline void Cba_ManFree( Cba_Man_t * p ) Abc_NamDeref( p->pStrs ); Abc_NamDeref( p->pCons ); Abc_NamDeref( p->pMods ); + Vec_IntErase( &p->vNameMap ); + Vec_IntErase( &p->vUsed ); + Vec_IntErase( &p->vNameMap2 ); + Vec_IntErase( &p->vUsed2 ); Vec_StrErase( &p->vOut ); Vec_StrErase( &p->vOut2 ); ABC_FREE( p->pName ); ABC_FREE( p->pSpec ); ABC_FREE( p ); } +static inline int Cba_ManGetMap( Cba_Man_t * p, int i ) +{ + return Vec_IntGetEntry(&p->vNameMap, i); +} +static inline void Cba_ManSetMap( Cba_Man_t * p, int i, int x ) +{ + assert( Vec_IntGetEntry(&p->vNameMap, i) == 0 ); + Vec_IntSetEntry( &p->vNameMap, i, x ); + Vec_IntPush( &p->vUsed, i ); +} +static inline void Cba_ManCleanMap( Cba_Man_t * p ) +{ + int i, Entry; + Vec_IntForEachEntry( &p->vUsed, Entry, i ) + Vec_IntWriteEntry( &p->vNameMap, Entry, 0 ); + Vec_IntClear( &p->vUsed ); +} +static inline int Cba_NtkGetMap( Cba_Ntk_t * p, int i ) { return Cba_ManGetMap(p->pDesign, i); } +static inline void Cba_NtkSetMap( Cba_Ntk_t * p, int i, int x ) { Cba_ManSetMap(p->pDesign, i, x); } +static inline void Cba_NtkCleanMap( Cba_Ntk_t * p ) { Cba_ManCleanMap(p->pDesign); } + +static inline int Cba_ManGetMap2( Cba_Man_t * p, int i ) +{ + return Vec_IntGetEntry(&p->vNameMap2, i); +} +static inline void Cba_ManSetMap2( Cba_Man_t * p, int i, int x ) +{ + assert( Vec_IntGetEntry(&p->vNameMap2, i) == 0 ); + Vec_IntSetEntry( &p->vNameMap2, i, x ); + Vec_IntPush( &p->vUsed2, i ); +} +static inline void Cba_ManCleanMap2( Cba_Man_t * p ) +{ + int i, Entry; + Vec_IntForEachEntry( &p->vUsed2, Entry, i ) + Vec_IntWriteEntry( &p->vNameMap2, Entry, 0 ); + Vec_IntClear( &p->vUsed2 ); +} +static inline int Cba_NtkGetMap2( Cba_Ntk_t * p, int i ) { return Cba_ManGetMap2(p->pDesign, i); } +static inline void Cba_NtkSetMap2( Cba_Ntk_t * p, int i, int x ) { Cba_ManSetMap2(p->pDesign, i, x); } +static inline void Cba_NtkCleanMap2( Cba_Ntk_t * p ) { Cba_ManCleanMap2(p->pDesign); } + static inline int Cba_ManNewConstId( Cba_Man_t * p, Vec_Str_t * vBits ) { Vec_Str_t * vOut = &p->vOut; @@ -859,6 +916,10 @@ static inline int Cba_ManMemory( Cba_Man_t * p ) nMem += Abc_NamMemUsed(p->pStrs); nMem += Abc_NamMemUsed(p->pCons); nMem += Abc_NamMemUsed(p->pMods); + nMem += (int)Vec_IntMemory(&p->vNameMap ); + nMem += (int)Vec_IntMemory(&p->vUsed ); + nMem += (int)Vec_StrMemory(&p->vOut ); + nMem += (int)Vec_StrMemory(&p->vOut2 ); nMem += (int)Vec_PtrMemory(&p->vNtks); Cba_ManForEachNtk( p, pNtk, i ) nMem += Cba_NtkMemory( pNtk ); @@ -915,7 +976,7 @@ static inline void Cba_ManPrintStats( Cba_Man_t * p, int nModules, int fVerbose printf( "%-12s : ", Cba_ManName(p) ); printf( "pi =%5d ", Cba_NtkPiNum(pRoot) ); printf( "po =%5d ", Cba_NtkPoNum(pRoot) ); - printf( "mod =%6d ", Cba_ManNtkNum(p) ); + printf( "mod =%5d ", Cba_ManNtkNum(p) ); printf( "box =%5d ", nPrims + nUsers ); printf( "prim =%5d ", nPrims ); printf( "user =%5d ", nUsers ); @@ -931,11 +992,16 @@ static inline void Cba_ManPrintStats( Cba_Man_t * p, int nModules, int fVerbose } - /*=== cbaBlast.c =============================================================*/ +extern Gia_Man_t * Cba_ManBlast( Cba_Man_t * p, int fBarBufs, int fVerbose ); +extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ); +extern Cba_Man_t * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc ); /*=== cbaCba.c ===============================================================*/ +extern Cba_Man_t * Cba_ManReadCba( char * pFileName ); +extern void Cba_ManWriteCba( char * pFileName, Cba_Man_t * p ); /*=== cbaCom.c ===============================================================*/ /*=== cbaNtk.c ===============================================================*/ +//extern void Cba_ManPrepareTypeNames( Cba_Man_t * p ); extern void Cba_NtkObjOrder( Cba_Ntk_t * p, Vec_Int_t * vObjs, Vec_Int_t * vNameIds ); extern int Cba_NtkCiFonNum( Cba_Ntk_t * p ); extern int Cba_NtkCoFinNum( Cba_Ntk_t * p ); @@ -946,22 +1012,20 @@ extern Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p, int TypeBuf ); extern Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs ); extern Cba_Man_t * Cba_ManDeriveFromGia( Gia_Man_t * pGia ); extern Cba_Man_t * Cba_ManInsertGroup( Cba_Man_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ); - -//extern void Cba_ManPrepareTypeNames( Cba_Man_t * p ); - /*=== cbaReadBlif.c ==========================================================*/ -extern Vec_Ptr_t * Prs_ManReadBlif( char * pFileName ); +extern Cba_Man_t * Cba_ManReadBlif( char * pFileName ); /*=== cbaReadVer.c ===========================================================*/ -extern Vec_Ptr_t * Prs_ManReadVerilog( char * pFileName ); +extern Cba_Man_t * Cba_ManReadVerilog( char * pFileName ); /*=== cbaWriteBlif.c =========================================================*/ -//extern void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * p ); -//extern void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p ); +extern void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * p ); +extern void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p ); /*=== cbaWriteVer.c ==========================================================*/ extern void Prs_ManWriteVerilog( char * pFileName, Vec_Ptr_t * p ); extern void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p, int fInlineConcat ); ABC_NAMESPACE_HEADER_END + #endif //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaBlast.c b/src/base/cba/cbaBlast.c index 87a5b5cd..70298b47 100644 --- a/src/base/cba/cbaBlast.c +++ b/src/base/cba/cbaBlast.c @@ -1,12 +1,12 @@ /**CFile**************************************************************** - FileName [cba.c] + FileName [cbaBlast.c] SystemName [ABC: Logic synthesis and verification system.] - PackageName [Verilog parser.] + PackageName [Hierarchical word-level netlist.] - Synopsis [Parses several flavors of word-level Verilog.] + Synopsis [Collapsing word-level design.] Author [Alan Mishchenko] @@ -14,11 +14,15 @@ Date [Ver. 1.0. Started - July 21, 2015.] - Revision [$Id: cba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] + Revision [$Id: cbaBlast.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] ***********************************************************************/ #include "cba.h" +#include "base/abc/abc.h" +#include "map/mio/mio.h" +#include "bool/dec/dec.h" +#include "base/main/mainInt.h" ABC_NAMESPACE_IMPL_START @@ -41,7 +45,31 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ +Gia_Man_t * Cba_ManBlast( Cba_Man_t * p, int fBarBufs, int fVerbose ) +{ + return NULL; +} +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ) +{ + return NULL; +} +Cba_Man_t * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc ) +{ + Abc_Ntk_t * pNtk = (Abc_Ntk_t *)pAbc; + return (Cba_Man_t *)pNtk; +} //////////////////////////////////////////////////////////////////////// /// END OF FILE /// diff --git a/src/base/cba/cbaCba.c b/src/base/cba/cbaCba.c index 87a5b5cd..2275c948 100644 --- a/src/base/cba/cbaCba.c +++ b/src/base/cba/cbaCba.c @@ -1,12 +1,12 @@ /**CFile**************************************************************** - FileName [cba.c] + FileName [cbaCba.c] SystemName [ABC: Logic synthesis and verification system.] - PackageName [Verilog parser.] + PackageName [Hierarchical word-level netlist.] - Synopsis [Parses several flavors of word-level Verilog.] + Synopsis [Reading binary representation.] Author [Alan Mishchenko] @@ -14,7 +14,7 @@ Date [Ver. 1.0. Started - July 21, 2015.] - Revision [$Id: cba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] + Revision [$Id: cbaCba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] ***********************************************************************/ @@ -41,7 +41,13 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ - +Cba_Man_t * Cba_ManReadCba( char * pFileName ) +{ + return NULL; +} +void Cba_ManWriteCba( char * pFileName, Cba_Man_t * p ) +{ +} //////////////////////////////////////////////////////////////////////// /// END OF FILE /// diff --git a/src/base/cba/cbaCom.c b/src/base/cba/cbaCom.c index 23cc869b..ca0f203d 100644 --- a/src/base/cba/cbaCom.c +++ b/src/base/cba/cbaCom.c @@ -28,7 +28,6 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -/* static int Cba_CommandRead ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Cba_CommandWrite ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Cba_CommandPs ( Abc_Frame_t * pAbc, int argc, char ** argv ); @@ -37,11 +36,10 @@ static int Cba_CommandGet ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Cba_CommandClp ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Cba_CommandCec ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Cba_CommandTest ( Abc_Frame_t * pAbc, int argc, char ** argv ); -*/ -static inline Cba_Man_t * Cba_AbcGetMan( Abc_Frame_t * pAbc ) { return (Cba_Man_t *)pAbc->pAbcCba; } -static inline void Cba_AbcFreeMan( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcCba ) Cba_ManFree(Cba_AbcGetMan(pAbc)); } -static inline void Cba_AbcUpdateMan( Abc_Frame_t * pAbc, Cba_Man_t * p ) { Cba_AbcFreeMan(pAbc); pAbc->pAbcCba = p; } +static inline Cba_Man_t * Cba_AbcGetMan( Abc_Frame_t * pAbc ) { return (Cba_Man_t *)pAbc->pAbcCba; } +static inline void Cba_AbcFreeMan( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcCba ) Cba_ManFree(Cba_AbcGetMan(pAbc)); } +static inline void Cba_AbcUpdateMan( Abc_Frame_t * pAbc, Cba_Man_t * p ) { Cba_AbcFreeMan(pAbc); pAbc->pAbcCba = p; } //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -60,7 +58,6 @@ static inline void Cba_AbcUpdateMan( Abc_Frame_t * pAbc, Cba_Man_t * p ) ******************************************************************************/ void Cba_Init( Abc_Frame_t * pAbc ) { -/* Cmd_CommandAdd( pAbc, "New word level", "@read", Cba_CommandRead, 0 ); Cmd_CommandAdd( pAbc, "New word level", "@write", Cba_CommandWrite, 0 ); Cmd_CommandAdd( pAbc, "New word level", "@ps", Cba_CommandPs, 0 ); @@ -69,7 +66,6 @@ void Cba_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "New word level", "@clp", Cba_CommandClp, 0 ); Cmd_CommandAdd( pAbc, "New word level", "@cec", Cba_CommandCec, 0 ); Cmd_CommandAdd( pAbc, "New word level", "@test", Cba_CommandTest, 0 ); -*/ } /**Function******************************************************************** @@ -89,8 +85,6 @@ void Cba_End( Abc_Frame_t * pAbc ) } -#if 0 - /**Function******************************************************************** Synopsis [] @@ -145,8 +139,7 @@ int Cba_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; } fclose( pFile ); - -#if 0 +/* // perform reading if ( fUseAbc || fUsePtr ) { @@ -162,48 +155,26 @@ int Cba_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) } Abc_NtkDelete( pAbcNtk ); } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - { - vDes = Prs_ManReadBlif( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Prs_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Prs_ManVecFree( vDes ); - } + else +*/ + if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) + p = Cba_ManReadBlif( pFileName ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - { - vDes = Prs_ManReadVerilog( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Prs_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Prs_ManVecFree( vDes ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "smt" ) ) - { - vDes = NULL;//Prs_ManReadSmt( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Prs_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Prs_ManVecFree( vDes ); - } + p = Cba_ManReadVerilog( pFileName ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) - { p = Cba_ManReadCba( pFileName ); - } else { printf( "Unrecognized input file extension.\n" ); return 0; } Cba_AbcUpdateMan( pAbc, p ); - -#endif return 0; usage: Abc_Print( -2, "usage: @read [-apvh] <file_name>\n" ); - Abc_Print( -2, "\t reads hierarchical design in BLIF or Verilog\n" ); - Abc_Print( -2, "\t-a : toggle using old ABC parser [default = %s]\n", fUseAbc? "yes": "no" ); - Abc_Print( -2, "\t-p : toggle using Ptr construction [default = %s]\n", fUsePtr? "yes": "no" ); + Abc_Print( -2, "\t reads hierarchical design\n" ); +// Abc_Print( -2, "\t-a : toggle using old ABC parser [default = %s]\n", fUseAbc? "yes": "no" ); +// Abc_Print( -2, "\t-p : toggle using Ptr construction [default = %s]\n", fUsePtr? "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; @@ -224,19 +195,15 @@ int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) { Cba_Man_t * p = Cba_AbcGetMan(pAbc); char * pFileName = NULL; - int fUseAssign = 1; - int fUsePtr = 0; + int fInclineCats = 1; int c, fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "apvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "cvh" ) ) != EOF ) { switch ( c ) { - case 'a': - fUseAssign ^= 1; - break; - case 'p': - fUsePtr ^= 1; + case 'c': + fInclineCats ^= 1; break; case 'v': fVerbose ^= 1; @@ -253,7 +220,6 @@ int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; } -#if 0 if ( argc == globalUtilOptind + 1 ) pFileName = argv[globalUtilOptind]; else if ( argc == globalUtilOptind && p ) @@ -267,21 +233,7 @@ int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) Cba_ManWriteBlif( pFileName, p ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - { - if ( fUsePtr ) - { - Vec_Ptr_t * vPtr = Cba_PtrDeriveFromCba( p ); - if ( vPtr == NULL ) - printf( "Converting to Ptr has failed.\n" ); - else - { - Cba_PtrDumpVerilog( pFileName, vPtr ); - Cba_PtrFree( vPtr ); - } - } - else - Cba_ManWriteVerilog( pFileName, p, fUseAssign ); - } + Cba_ManWriteVerilog( pFileName, p, fInclineCats ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) Cba_ManWriteCba( pFileName, p ); else @@ -289,14 +241,11 @@ int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) printf( "Unrecognized output file extension.\n" ); return 0; } - -#endif return 0; usage: - Abc_Print( -2, "usage: @write [-apvh]\n" ); + Abc_Print( -2, "usage: @write [-cvh]\n" ); Abc_Print( -2, "\t writes the design into a file in BLIF or Verilog\n" ); - Abc_Print( -2, "\t-a : toggle using assign-statement for primitives [default = %s]\n", fUseAssign? "yes": "no" ); - Abc_Print( -2, "\t-p : toggle using Ptr construction (mapped Verilog only) [default = %s]\n", fUsePtr? "yes": "no" ); + Abc_Print( -2, "\t-c : toggle inlining input concatenations [default = %s]\n", fInclineCats? "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; @@ -348,11 +297,7 @@ int Cba_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( 1, "Cba_CommandPs(): There is no current design.\n" ); return 0; } - -#if 0 Cba_ManPrintStats( p, nModules, fVerbose ); - -#endif return 0; usage: Abc_Print( -2, "usage: @ps [-M num] [-vh]\n" ); @@ -401,17 +346,13 @@ int Cba_CommandPut( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( 1, "Cba_CommandPut(): There is no current design.\n" ); return 0; } - -#if 0 - pGia = Cba_ManExtract( p, fBarBufs, fVerbose ); + pGia = Cba_ManBlast( p, fBarBufs, fVerbose ); if ( pGia == NULL ) { Abc_Print( 1, "Cba_CommandPut(): Conversion to AIG has failed.\n" ); return 0; } Abc_FrameUpdateGia( pAbc, pGia ); - -#endif return 0; usage: Abc_Print( -2, "usage: @put [-bvh]\n" ); @@ -460,7 +401,6 @@ int Cba_CommandGet( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; } -#if 0 if ( fMapped ) { if ( pAbc->pNtkCur == NULL ) @@ -468,7 +408,7 @@ int Cba_CommandGet( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( 1, "Cba_CommandGet(): There is no current mapped design.\n" ); return 0; } - pNew = (Cba_Man_t *)Cba_ManInsertAbc( p, pAbc->pNtkCur ); + pNew = Cba_ManInsertAbc( p, pAbc->pNtkCur ); } else { @@ -480,8 +420,6 @@ int Cba_CommandGet( Abc_Frame_t * pAbc, int argc, char ** argv ) pNew = Cba_ManInsertGia( p, pAbc->pGia ); } Cba_AbcUpdateMan( pAbc, pNew ); - -#endif return 0; usage: Abc_Print( -2, "usage: @get [-mvh]\n" ); @@ -526,12 +464,8 @@ int Cba_CommandClp( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( 1, "Cba_CommandGet(): There is no current design.\n" ); return 0; } - -#if 0 pNew = Cba_ManCollapse( p, CBA_BOX_BUF ); Cba_AbcUpdateMan( pAbc, pNew ); - -#endif return 0; usage: Abc_Print( -2, "usage: @clp [-vh]\n" ); @@ -554,11 +488,10 @@ usage: ******************************************************************************/ int Cba_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) { - Cba_Man_t * p = Cba_AbcGetMan(pAbc); + Cba_Man_t * p = Cba_AbcGetMan(pAbc), * pTemp; Gia_Man_t * pFirst, * pSecond, * pMiter; Cec_ParCec_t ParsCec, * pPars = &ParsCec; - Vec_Ptr_t * vDes; - char * FileName, * pStr, ** pArgvNew; + char * pFileName, * pStr, ** pArgvNew; int c, nArgcNew, fDumpMiter = 0; FILE * pFile; Cec_ManCecSetDefaultParams( pPars ); @@ -582,7 +515,6 @@ int Cba_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; } -#if 0 pArgvNew = argv + globalUtilOptind; nArgcNew = argc - globalUtilOptind; if ( nArgcNew != 1 ) @@ -592,41 +524,42 @@ int Cba_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "File name is not given on the command line.\n" ); return 1; } - FileName = p->pSpec; + pFileName = p->pSpec; } else - FileName = pArgvNew[0]; + pFileName = pArgvNew[0]; // fix the wrong symbol - for ( pStr = FileName; *pStr; pStr++ ) + for ( pStr = pFileName; *pStr; pStr++ ) if ( *pStr == '>' ) *pStr = '\\'; - if ( (pFile = fopen( FileName, "r" )) == NULL ) + if ( (pFile = fopen( pFileName, "r" )) == NULL ) { - Abc_Print( -1, "Cannot open input file \"%s\". ", FileName ); - if ( (FileName = Extra_FileGetSimilarName( FileName, ".v", ".blif", NULL, NULL, NULL )) ) - Abc_Print( 1, "Did you mean \"%s\"?", FileName ); + Abc_Print( -1, "Cannot open input file \"%s\". ", pFileName ); + if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".blif", NULL, NULL, NULL )) ) + Abc_Print( 1, "Did you mean \"%s\"?", pFileName ); Abc_Print( 1, "\n" ); return 1; } fclose( pFile ); // extract AIG from the current design - pFirst = Cba_ManExtract( p, 0, 0 ); + pFirst = Cba_ManBlast( p, 0, 0 ); if ( pFirst == NULL ) { Abc_Print( -1, "Extracting AIG from the current design has failed.\n" ); return 0; } // extract AIG from the second design - if ( !strcmp( Extra_FileNameExtension(FileName), "blif" ) ) - vDes = Prs_ManReadBlif( FileName ); - else if ( !strcmp( Extra_FileNameExtension(FileName), "v" ) ) - vDes = Prs_ManReadVerilog( FileName ); + + if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) + pTemp = Cba_ManReadBlif( pFileName ); + else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) + pTemp = Cba_ManReadVerilog( pFileName ); + else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) + pTemp = Cba_ManReadCba( pFileName ); else assert( 0 ); - p = Prs_ManBuildCba( FileName, vDes ); - Prs_ManVecFree( vDes ); - pSecond = Cba_ManExtract( p, 0, 0 ); - Cba_ManFree( p ); + pSecond = Cba_ManBlast( pTemp, 0, 0 ); + Cba_ManFree( pTemp ); if ( pSecond == NULL ) { Gia_ManStop( pFirst ); @@ -648,8 +581,6 @@ int Cba_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) } Gia_ManStop( pFirst ); Gia_ManStop( pSecond ); - -#endif return 0; usage: Abc_Print( -2, "usage: @cec [-vh]\n" ); @@ -672,6 +603,8 @@ usage: ******************************************************************************/ int Cba_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv ) { + extern void Prs_ManReadBlifTest(); + Cba_Man_t * p = Cba_AbcGetMan(pAbc); int c, fVerbose = 0; Extra_UtilGetoptReset(); @@ -688,11 +621,14 @@ int Cba_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv ) goto usage; } } +/* if ( p == NULL ) { Abc_Print( 1, "Cba_CommandTest(): There is no current design.\n" ); return 0; } +*/ + Prs_ManReadBlifTest(); return 0; usage: Abc_Print( -2, "usage: @test [-vh]\n" ); @@ -702,8 +638,6 @@ usage: return 1; } -#endif - //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaNtk.c b/src/base/cba/cbaNtk.c index 34bc4253..7b16d789 100644 --- a/src/base/cba/cbaNtk.c +++ b/src/base/cba/cbaNtk.c @@ -1,12 +1,12 @@ /**CFile**************************************************************** - FileName [cba.c] + FileName [cbaNtk.c] SystemName [ABC: Logic synthesis and verification system.] - PackageName [Verilog parser.] + PackageName [Hierarchical word-level netlist.] - Synopsis [Parses several flavors of word-level Verilog.] + Synopsis [Network manipulation.] Author [Alan Mishchenko] @@ -14,7 +14,7 @@ Date [Ver. 1.0. Started - July 21, 2015.] - Revision [$Id: cba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] + Revision [$Id: cbaNtk.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] ***********************************************************************/ diff --git a/src/base/cba/cbaPrs.h b/src/base/cba/cbaPrs.h index e8dc2602..fa7534ec 100644 --- a/src/base/cba/cbaPrs.h +++ b/src/base/cba/cbaPrs.h @@ -60,6 +60,7 @@ struct Prs_Ntk_t_ unsigned fHasCXs : 1; unsigned fHasCZs : 1; Abc_Nam_t * pStrs; + Abc_Nam_t * pSops; // interface Vec_Int_t vOrder; // order of signals // signal names @@ -89,6 +90,7 @@ struct Prs_Man_t_ char * pLimit; // end of file char * pCur; // current position Abc_Nam_t * pStrs; // string manager + Abc_Nam_t * pSops; // cover manager Prs_Ntk_t * pNtk; // current network Vec_Ptr_t * vNtks; // input networks // temporary data @@ -107,6 +109,7 @@ struct Prs_Man_t_ static inline Prs_Ntk_t * Prs_ManNtk( Vec_Ptr_t * vPrs, int i ) { return i >= 0 && i < Vec_PtrSize(vPrs) ? (Prs_Ntk_t *)Vec_PtrEntry(vPrs, i) : NULL; } static inline Prs_Ntk_t * Prs_ManRoot( Vec_Ptr_t * vPrs ) { return Prs_ManNtk(vPrs, 0); } static inline Abc_Nam_t * Prs_ManNameMan( Vec_Ptr_t * vPrs ) { return Prs_ManRoot(vPrs)->pStrs; } +static inline Abc_Nam_t * Prs_ManFuncMan( Vec_Ptr_t * vPrs ) { return Prs_ManRoot(vPrs)->pSops; } static inline int Prs_NtkId( Prs_Ntk_t * p ) { return p->iModuleName; } static inline int Prs_NtkPioNum( Prs_Ntk_t * p ) { return Vec_IntSize(&p->vInouts); } @@ -115,6 +118,7 @@ static inline int Prs_NtkPoNum( Prs_Ntk_t * p ) { return static inline int Prs_NtkBoxNum( Prs_Ntk_t * p ) { return Vec_IntSize(&p->vObjs); } static inline int Prs_NtkObjNum( Prs_Ntk_t * p ) { return Prs_NtkPioNum(p) + Prs_NtkPiNum(p) + Prs_NtkPoNum(p) + Prs_NtkBoxNum(p); } static inline char * Prs_NtkStr( Prs_Ntk_t * p, int h ) { return Abc_NamStr(p->pStrs, h); } +static inline char * Prs_NtkSop( Prs_Ntk_t * p, int h ) { return Abc_NamStr(p->pSops, h); } static inline char * Prs_NtkName( Prs_Ntk_t * p ) { return Prs_NtkStr(p, Prs_NtkId(p)); } static inline int Prs_NtkSigName( Prs_Ntk_t * p, int i ) { if (!p->fSlices) return i; assert(Abc_Lit2Att2(i) == CBA_PRS_NAME); return Abc_Lit2Var2(i); } @@ -182,6 +186,7 @@ static inline void Prs_ManInitializeNtk( Prs_Man_t * p, int iName, int fSlices ) p->pNtk->iModuleName = iName; p->pNtk->fSlices = fSlices; p->pNtk->pStrs = Abc_NamRef( p->pStrs ); + p->pNtk->pSops = Abc_NamRef( p->pSops ); Vec_PtrPush( p->vNtks, p->pNtk ); } static inline void Prs_ManFinalizeNtk( Prs_Man_t * p ) @@ -264,14 +269,17 @@ static inline Prs_Man_t * Prs_ManAlloc( char * pFileName ) p->pLimit = pLimit; p->pCur = pBuffer; p->pStrs = Abc_NamStart( 1000, 24 ); + p->pSops = Abc_NamStart( 100, 24 ); p->vNtks = Vec_PtrAlloc( 100 ); + Abc_NamStrFindOrAdd( p->pSops, " 0\n", NULL ); + Abc_NamStrFindOrAdd( p->pSops, " 1\n", NULL ); return p; } static inline void Prs_NtkFree( Prs_Ntk_t * p ) { - if ( p->pStrs ) - Abc_NamDeref( p->pStrs ); + if ( p->pStrs ) Abc_NamDeref( p->pStrs ); + if ( p->pSops ) Abc_NamDeref( p->pSops ); Vec_IntErase( &p->vOrder ); Vec_IntErase( &p->vInouts ); Vec_IntErase( &p->vInputs ); @@ -298,10 +306,9 @@ static inline void Prs_ManVecFree( Vec_Ptr_t * vPrs ) static inline void Prs_ManFree( Prs_Man_t * p ) { - if ( p->pStrs ) - Abc_NamDeref( p->pStrs ); - if ( p->vNtks ) - Prs_ManVecFree( p->vNtks ); + if ( p->pStrs ) Abc_NamDeref( p->pStrs ); + if ( p->pSops ) Abc_NamDeref( p->pSops ); + if ( p->vNtks ) Prs_ManVecFree( p->vNtks ); // temporary Vec_StrErase( &p->vCover ); Vec_IntErase( &p->vTemp ); diff --git a/src/base/cba/cbaReadBlif.c b/src/base/cba/cbaReadBlif.c index a9a752e2..37e313e2 100644 --- a/src/base/cba/cbaReadBlif.c +++ b/src/base/cba/cbaReadBlif.c @@ -234,8 +234,8 @@ static inline void Prs_ManSaveCover( Prs_Man_t * p ) } assert( Vec_StrSize(&p->vCover) > 0 ); Vec_StrPush( &p->vCover, '\0' ); - //iToken = Abc_NamStrFindOrAdd( p->pStrs, Vec_StrArray(&p->vCover), NULL ); - iToken = Ptr_SopToType( Vec_StrArray(&p->vCover) ); +// iToken = Ptr_SopToType( Vec_StrArray(&p->vCover) ); + iToken = Abc_NamStrFindOrAdd( p->pSops, Vec_StrArray(&p->vCover), NULL ); Vec_StrClear( &p->vCover ); // set the cover to the module of this box assert( Prs_BoxNtk(p->pNtk, Prs_NtkBoxNum(p->pNtk)-1) == 1 ); // default const 0 @@ -433,17 +433,211 @@ void Prs_ManReadBlifTest() abctime clk = Abc_Clock(); extern void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ); // Vec_Ptr_t * vPrs = Prs_ManReadBlif( "aga/ray/ray_hie_oper.blif" ); - Vec_Ptr_t * vPrs = Prs_ManReadBlif( "c/hie/dump/1/netlist_1_out8.blif" ); +// Vec_Ptr_t * vPrs = Prs_ManReadBlif( "c/hie/dump/1/netlist_1_out8.blif" ); + Vec_Ptr_t * vPrs = Prs_ManReadBlif( "add2.blif" ); if ( !vPrs ) return; printf( "Finished reading %d networks. ", Vec_PtrSize(vPrs) ); printf( "NameIDs = %d. ", Abc_NamObjNumMax(Prs_ManNameMan(vPrs)) ); printf( "Memory = %.2f MB. ", 1.0*Prs_ManMemory(vPrs)/(1<<20) ); Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); // Abc_NamPrint( p->pStrs ); - Prs_ManWriteBlif( "c/hie/dump/1/netlist_1_out8_out.blif", vPrs ); + Prs_ManWriteBlif( "add2_out.blif", vPrs ); Prs_ManVecFree( vPrs ); } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Prs_CreateBlifFindFon( Cba_Ntk_t * p, int NameId ) +{ + int iFon = Cba_NtkGetMap( p, NameId ); + if ( iFon ) + return iFon; + printf( "Network \"%s\": Signal \"%s\" is not driven.\n", Cba_NtkName(p), Cba_NtkStr(p, NameId) ); + return 0; +} +void Prs_CreateBlifPio( Cba_Ntk_t * p, Prs_Ntk_t * pNtk ) +{ + int i, NameId, iObj, iFon; + Cba_NtkCleanObjFuncs( p ); + Cba_NtkCleanObjNames( p ); + Cba_NtkCleanFonNames( p ); + // create inputs + Prs_NtkForEachPi( pNtk, NameId, i ) + { + iObj = Cba_ObjAlloc( p, CBA_OBJ_PI, 0, 1 ); + Cba_ObjSetName( p, iObj, NameId ); + iFon = Cba_ObjFon0(p, iObj); + Cba_FonSetName( p, iFon, NameId ); + Cba_NtkSetMap( p, NameId, iFon ); + Vec_IntPush( &p->vOrder, iObj ); + } + // create outputs + Prs_NtkForEachPo( pNtk, NameId, i ) + { + iObj = Cba_ObjAlloc( p, CBA_OBJ_PO, 1, 0 ); + Cba_ObjSetName( p, iObj, NameId ); + Vec_IntPush( &p->vOrder, iObj ); + } +} +int Prs_CreateBlifNtk( Cba_Ntk_t * p, Prs_Ntk_t * pNtk ) +{ + Vec_Int_t * vBox; + int i, k, iObj, iTerm, iFon, FormId, ActId; + // map inputs + Cba_NtkCleanMap( p ); + Cba_NtkForEachPi( p, iObj, i ) + Cba_NtkSetMap( p, Cba_ObjName(p, iObj), Cba_ObjFon0(p, iObj) ); + // create objects + Prs_NtkForEachBox( pNtk, vBox, i ) + { + int FuncId = Prs_BoxNtk(pNtk, i); + assert( Prs_BoxIONum(pNtk, i) > 0 ); + assert( Vec_IntSize(vBox) % 2 == 0 ); + if ( FuncId == -1 ) // latch + { + iObj = Cba_ObjAlloc( p, CBA_BOX_DFFRS, 4, 1 ); + Cba_NtkSetMap( p, Vec_IntEntry(vBox, 3), Cba_ObjFon0(p, iObj) ); // latch output + Cba_ObjSetFunc( p, iObj, Prs_BoxName(pNtk, i)+1 ); // init + 1 + } + else if ( Prs_BoxIsNode(pNtk, i) ) // node + { + iObj = Cba_ObjAlloc( p, CBA_BOX_NODE, Prs_BoxIONum(pNtk, i)-1, 1 ); + Cba_FonSetName( p, Cba_ObjFon0(p, iObj), Vec_IntEntryLast(vBox) ); // node output + Cba_NtkSetMap( p, Vec_IntEntryLast(vBox), Cba_ObjFon0(p, iObj) ); + Cba_ObjSetFunc( p, iObj, FuncId ); + } + else // box + { + Cba_Ntk_t * pBox = Cba_ManNtkFind( p->pDesign, Prs_NtkStr(pNtk, FuncId) ); + iObj = Cba_ObjAlloc( p, CBA_OBJ_BOX, Cba_NtkPiNum(pBox), Cba_NtkPoNum(pBox) ); + Cba_ObjSetFunc( p, iObj, Cba_NtkId(pBox) ); + // mark PO objects + Cba_NtkCleanMap2( p ); + Cba_NtkForEachPo( pBox, iTerm, k ) + Cba_NtkSetMap2( p, Cba_ObjName(pBox, iTerm), k+1 ); + // map box fons + Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) + if ( Cba_NtkGetMap2(p, FormId) ) + { + iFon = Cba_ObjFon(p, iObj, Cba_NtkGetMap2(p, FormId)-1); + Cba_FonSetName( p, iFon, ActId ); + Cba_NtkSetMap( p, ActId, iFon ); + } + } + } + // connect objects + Prs_NtkForEachBox( pNtk, vBox, i ) + { + iObj = Cba_NtkPiNum(p) + Cba_NtkPoNum(p) + i + 1; + if ( Prs_BoxNtk(pNtk, i) == -1 ) // latch + { + assert( Cba_ObjType(p, iObj) == CBA_BOX_DFFRS ); + iFon = Prs_CreateBlifFindFon( p, Vec_IntEntry(vBox, 1) ); // latch input + if ( iFon ) + Cba_ObjSetFinFon( p, iObj, 0, iFon ); + } + else if ( Prs_BoxIsNode(pNtk, i) ) // node + { + assert( Cba_ObjType(p, iObj) == CBA_BOX_NODE ); + Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) + { + if ( k == 2 * Cba_ObjFinNum(p, iObj) ) // stop at node output + break; + iFon = Prs_CreateBlifFindFon( p, ActId ); + if ( iFon ) + Cba_ObjSetFinFon( p, iObj, k/2, iFon ); + } + } + else // box + { + // mark PI objects + Cba_Ntk_t * pBox = Cba_ObjNtk(p, iObj); + assert( Cba_NtkPiNum(pBox) == Cba_ObjFinNum(p, iObj) ); + assert( Cba_NtkPoNum(pBox) == Cba_ObjFonNum(p, iObj) ); + Cba_NtkCleanMap2( p ); + Cba_NtkForEachPi( pBox, iTerm, k ) + Cba_NtkSetMap2( p, Cba_ObjName(pBox, iTerm), k+1 ); + // connect box fins + Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) + if ( Cba_NtkGetMap2(p, FormId) ) + { + iFon = Prs_CreateBlifFindFon( p, ActId ); + if ( iFon ) + Cba_ObjSetFinFon( p, iObj, Cba_NtkGetMap2(p, FormId)-1, iFon ); + } + } + } + // connect outputs + Cba_NtkForEachPo( p, iObj, i ) + { + iFon = Prs_CreateBlifFindFon( p, Cba_ObjName(p, iObj) ); + if ( iFon ) + Cba_ObjSetFinFon( p, iObj, 0, iFon ); + } + return 0; +} +Cba_Man_t * Prs_ManBuildCbaBlif( char * pFileName, Vec_Ptr_t * vDes ) +{ + Prs_Ntk_t * pPrsNtk; int i, fError = 0; + Prs_Ntk_t * pPrsRoot = Prs_ManRoot(vDes); + // start the manager + Abc_Nam_t * pStrs = Abc_NamRef(pPrsRoot->pStrs); + Abc_Nam_t * pCons = Abc_NamRef(pPrsRoot->pSops); + Abc_Nam_t * pMods = Abc_NamStart( 100, 24 ); + Cba_Man_t * p = Cba_ManAlloc( pFileName, Vec_PtrSize(vDes), pStrs, pCons, pMods ); + // initialize networks + Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pPrsNtk, i ) + { + Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, Prs_NtkId(pPrsNtk), Prs_NtkPiNum(pPrsNtk), Prs_NtkPoNum(pPrsNtk), Prs_NtkObjNum(pPrsNtk), 100, 100 ); + Prs_CreateBlifPio( pNtk, pPrsNtk ); + Cba_NtkAdd( p, pNtk ); + } + // create networks + Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pPrsNtk, i ) + { + printf( "Elaboration module \"%s\"...\n", Prs_NtkName(pPrsNtk), vDes ); + fError = Prs_CreateBlifNtk( Cba_ManNtk(p, i+1), pPrsNtk ); + if ( fError ) + break; + } + if ( fError ) + printf( "Quitting because of errors.\n" ); + else + Cba_ManPrepareSeq( p ); + return p; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Cba_Man_t * Cba_ManReadBlif( char * pFileName ) +{ + Cba_Man_t * p = NULL; + Vec_Ptr_t * vDes = Prs_ManReadBlif( pFileName ); + if ( vDes && Vec_PtrSize(vDes) ) + p = Prs_ManBuildCbaBlif( pFileName, vDes ); + if ( vDes ) + Prs_ManVecFree( vDes ); + return p; +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaReadVer.c b/src/base/cba/cbaReadVer.c index 67a7c3b7..10032a9f 100644 --- a/src/base/cba/cbaReadVer.c +++ b/src/base/cba/cbaReadVer.c @@ -865,6 +865,32 @@ void Prs_ManReadVerilogTest( char * pFileName ) Prs_ManVecFree( vPrs ); } +Cba_Man_t * Prs_ManBuildCbaVerilog( char * pFileName, Vec_Ptr_t * vDes ) +{ + return NULL; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Cba_Man_t * Cba_ManReadVerilog( char * pFileName ) +{ + Cba_Man_t * p = NULL; + Vec_Ptr_t * vDes = Prs_ManReadVerilog( pFileName ); + if ( vDes && Vec_PtrSize(vDes) ) + p = Prs_ManBuildCbaVerilog( pFileName, vDes ); + if ( vDes ) + Prs_ManVecFree( vDes ); + return p; +} //////////////////////////////////////////////////////////////////////// /// END OF FILE /// diff --git a/src/base/cba/cbaWriteBlif.c b/src/base/cba/cbaWriteBlif.c index 74ed2e42..9ddfe58f 100644 --- a/src/base/cba/cbaWriteBlif.c +++ b/src/base/cba/cbaWriteBlif.c @@ -72,7 +72,7 @@ static void Prs_ManWriteBlifLines( FILE * pFile, Prs_Ntk_t * p ) fprintf( pFile, ".names" ); Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) fprintf( pFile, " %s", Prs_NtkStr(p, ActId) ); - fprintf( pFile, "\n%s", Prs_NtkStr(p, NtkId) ); + fprintf( pFile, "\n%s", Prs_NtkSop(p, NtkId) ); } else // box { @@ -116,8 +116,6 @@ void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ) } -#if 0 - /**Function************************************************************* Synopsis [Write elaborated design.] @@ -129,76 +127,59 @@ void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ) SeeAlso [] ***********************************************************************/ -void Cba_ManWriteBlifGate( FILE * pFile, Cba_Ntk_t * p, Mio_Gate_t * pGate, Vec_Int_t * vFanins, int iObj ) -{ - int iFanin, i; - Vec_IntForEachEntry( vFanins, iFanin, i ) - fprintf( pFile, " %s=%s", Mio_GateReadPinName(pGate, i), Cba_ObjNameStr(p, iFanin) ); - fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate), Cba_ObjNameStr(p, iObj) ); - fprintf( pFile, "\n" ); -} -void Cba_ManWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, int iObj ) -{ - int iFanin, i; - Vec_IntForEachEntry( vFanins, iFanin, i ) - fprintf( pFile, " %s", Cba_ObjNameStr(p, iFanin) ); - if ( iObj >= 0 ) - fprintf( pFile, " %s", Cba_ObjNameStr(p, iObj) ); - fprintf( pFile, "\n" ); -} -void Cba_ManWriteBlifArray2( FILE * pFile, Cba_Ntk_t * p, int iObj ) -{ - int iTerm, i; - Cba_Ntk_t * pModel = Cba_BoxNtk( p, iObj ); - Cba_NtkForEachPi( pModel, iTerm, i ) - fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, Cba_BoxBi(p, iObj, i)) ); - Cba_NtkForEachPo( pModel, iTerm, i ) - fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, Cba_BoxBo(p, iObj, i)) ); - fprintf( pFile, "\n" ); -} void Cba_ManWriteBlifLines( FILE * pFile, Cba_Ntk_t * p ) { - int i, k, iTerm; - Cba_NtkForEachBox( p, i ) + int k, iObj, iFin, iFon; + Cba_NtkForEachBox( p, iObj ) { - if ( Cba_ObjIsBoxUser(p, i) ) + if ( Cba_ObjIsBoxUser(p, iObj) ) { + Cba_Ntk_t * pNtk = Cba_ObjNtk( p, iObj ); fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", Cba_NtkName(Cba_BoxNtk(p, i)) ); - Cba_ManWriteBlifArray2( pFile, p, i ); + fprintf( pFile, " %s", Cba_NtkName(pNtk) ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + fprintf( pFile, " %s=%s", Cba_ObjNameStr(pNtk, Cba_NtkPi(pNtk, k)), Cba_FonNameStr(p, iFon) ); + Cba_ObjForEachFon( p, iObj, iFon, k ) + fprintf( pFile, " %s=%s", Cba_ObjNameStr(pNtk, Cba_NtkPo(pNtk, k)), Cba_FonNameStr(p, iFon) ); + fprintf( pFile, "\n" ); } - else if ( Cba_ObjIsGate(p, i) ) + else if ( Cba_ObjIsGate(p, iObj) ) { - char * pGateName = Abc_NamStr(p->pDesign->pMods, Cba_BoxNtkId(p, i)); + char * pGateName = Abc_NamStr(p->pDesign->pMods, Cba_ObjNtkId( p, iObj )); Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); Mio_Gate_t * pGate = Mio_LibraryReadGateByName( pLib, pGateName, NULL ); fprintf( pFile, ".gate %s", pGateName ); - Cba_BoxForEachBi( p, i, iTerm, k ) - fprintf( pFile, " %s=%s", Mio_GateReadPinName(pGate, k), Cba_ObjNameStr(p, iTerm) ); - Cba_BoxForEachBo( p, i, iTerm, k ) - fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate), Cba_ObjNameStr(p, iTerm) ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + fprintf( pFile, " %s=%s", Mio_GateReadPinName(pGate, k), Cba_FonNameStr(p, iFon) ); + Cba_ObjForEachFon( p, iObj, iFon, k ) + fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate), Cba_FonNameStr(p, iFon) ); fprintf( pFile, "\n" ); } else { fprintf( pFile, ".names" ); - Cba_BoxForEachBi( p, i, iTerm, k ) - fprintf( pFile, " %s", Cba_ObjNameStr(p, Cba_ObjFanin(p, iTerm)) ); - Cba_BoxForEachBo( p, i, iTerm, k ) - fprintf( pFile, " %s", Cba_ObjNameStr(p, iTerm) ); - fprintf( pFile, "\n%s", Ptr_TypeToSop(Cba_ObjType(p, i)) ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + fprintf( pFile, " %s", Cba_FonNameStr(p, iFon) ); + fprintf( pFile, " %s", Cba_FonNameStr(p, Cba_ObjFon0(p, iObj)) ); + fprintf( pFile, "\n%s", Cba_NtkSop(p, Cba_ObjFunc(p, iObj)) ); } } } +void Cba_ManWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vObjs ) +{ + int iObj, i; + Vec_IntForEachEntry( vObjs, iObj, i ) + fprintf( pFile, " %s", Cba_ObjNameStr(p, iObj) ); + fprintf( pFile, "\n" ); +} void Cba_ManWriteBlifNtk( FILE * pFile, Cba_Ntk_t * p ) { - assert( Vec_IntSize(&p->vFanin) == Cba_NtkObjNum(p) ); // write header fprintf( pFile, ".model %s\n", Cba_NtkName(p) ); fprintf( pFile, ".inputs" ); - Cba_ManWriteBlifArray( pFile, p, &p->vInputs, -1 ); + Cba_ManWriteBlifArray( pFile, p, &p->vInputs ); fprintf( pFile, ".outputs" ); - Cba_ManWriteBlifArray( pFile, p, &p->vOutputs, -1 ); + Cba_ManWriteBlifArray( pFile, p, &p->vOutputs ); // write objects Cba_ManWriteBlifLines( pFile, p ); fprintf( pFile, ".end\n\n" ); @@ -221,13 +202,12 @@ void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p ) return; } fprintf( pFile, "# Design \"%s\" written via CBA package in ABC on %s\n\n", Cba_ManName(p), Extra_TimeStamp() ); - Cba_ManAssignInternWordNames( p ); +// Cba_ManAssignInternWordNames( p ); Cba_ManForEachNtk( p, pNtk, i ) Cba_ManWriteBlifNtk( pFile, pNtk ); fclose( pFile ); } -#endif //////////////////////////////////////////////////////////////////////// /// END OF FILE /// diff --git a/src/base/cba/cbaWriteVer.c b/src/base/cba/cbaWriteVer.c index 228656d0..ff585d4d 100644 --- a/src/base/cba/cbaWriteVer.c +++ b/src/base/cba/cbaWriteVer.c @@ -206,7 +206,7 @@ void Cba_ManCreatePrimMap( char ** pMap ) pMap[ CBA_BOX_SHARP ] = "&"; pMap[ CBA_BOX_SHARPL ] = "&"; pMap[ CBA_BOX_MUX ] = "?"; - pMap[ CBA_BOX_MAJ ] = "maj"; + pMap[ CBA_BOX_MAJ ] = NULL; pMap[ CBA_BOX_RAND ] = "&"; pMap[ CBA_BOX_RNAND ] = "~&"; pMap[ CBA_BOX_ROR ] = "|"; @@ -215,27 +215,27 @@ void Cba_ManCreatePrimMap( char ** pMap ) pMap[ CBA_BOX_RXNOR ] = "~^"; pMap[ CBA_BOX_LNOT ] = "!"; pMap[ CBA_BOX_LAND ] = "&&"; - pMap[ CBA_BOX_LNAND ] = "!&&"; + pMap[ CBA_BOX_LNAND ] = NULL; pMap[ CBA_BOX_LOR ] = "||"; - pMap[ CBA_BOX_LNOR ] = "!||"; + pMap[ CBA_BOX_LNOR ] = NULL; pMap[ CBA_BOX_LXOR ] = "^^"; - pMap[ CBA_BOX_LXNOR ] = "!^^"; - pMap[ CBA_BOX_NMUX ] = "??"; - pMap[ CBA_BOX_SEL ] = "?|"; - pMap[ CBA_BOX_PSEL ] = "?%"; - pMap[ CBA_BOX_ENC ] = "enc"; - pMap[ CBA_BOX_PENC ] = "penc"; - pMap[ CBA_BOX_DEC ] = "dec"; - pMap[ CBA_BOX_EDEC ] = "edec"; + pMap[ CBA_BOX_LXNOR ] = NULL; + pMap[ CBA_BOX_NMUX ] = NULL; + pMap[ CBA_BOX_SEL ] = NULL; + pMap[ CBA_BOX_PSEL ] = NULL; + pMap[ CBA_BOX_ENC ] = NULL; + pMap[ CBA_BOX_PENC ] = NULL; + pMap[ CBA_BOX_DEC ] = NULL; + pMap[ CBA_BOX_EDEC ] = NULL; pMap[ CBA_BOX_ADD ] = "+"; pMap[ CBA_BOX_SUB ] = "-"; pMap[ CBA_BOX_MUL ] = "*"; pMap[ CBA_BOX_DIV ] = "/"; - pMap[ CBA_BOX_MOD ] = "mod"; + pMap[ CBA_BOX_MOD ] = NULL; pMap[ CBA_BOX_REM ] = "%%"; pMap[ CBA_BOX_POW ] = "**"; pMap[ CBA_BOX_MIN ] = "-"; - pMap[ CBA_BOX_ABS ] = "abs"; + pMap[ CBA_BOX_ABS ] = NULL; pMap[ CBA_BOX_LTHAN ] = "<"; pMap[ CBA_BOX_LETHAN ] = "<="; pMap[ CBA_BOX_METHAN ] = ">="; @@ -244,14 +244,56 @@ void Cba_ManCreatePrimMap( char ** pMap ) pMap[ CBA_BOX_NEQU ] = "!="; pMap[ CBA_BOX_SHIL ] = "<<"; pMap[ CBA_BOX_SHIR ] = ">>"; - pMap[ CBA_BOX_ROTL ] = "rotL"; - pMap[ CBA_BOX_ROTR ] = "rotR"; + pMap[ CBA_BOX_ROTL ] = NULL; + pMap[ CBA_BOX_ROTR ] = NULL; } +// considers word-level signal and returns bit-level signal +int Cba_ObjFindOne( Cba_Ntk_t * p, int iFon ) +{ + int Range = Cba_FonRange( p, iFon ); + if ( Range == 1 ) + { + if ( Cba_FonIsConst(iFon) ) + return Cba_FonConst(iFon) == 1 ? 0 : -1; + return iFon; + } + assert( Range > 1 ); + if ( Cba_FonIsConst(iFon) ) + { + int i; char Digit = 0; + char * s = Cba_NtkConst( p, Cba_FonConst(iFon) ); + while ( *s != 'b' ) s++; + assert( *s == 'b' ); + for ( i = 1; i <= Range; i++ ) + { + if ( Digit == 0 ) + Digit = s[i]; + else if ( Digit != s[i] ) + return -1; + } + return s[1] == '0' ? 0 : -1; + } + else + { + int iObj = Cba_FonObj( p, iFon ); + int i, iFin, iFon, OneFon = ABC_INFINITY; + if ( Cba_ObjType(p, iObj) != CBA_BOX_CATIN ) + return -1; + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + if ( OneFon == ABC_INFINITY ) + OneFon = iFon; + else if ( OneFon != iFon ) + return -1; + assert( Cba_FonIsReal(OneFon) ); + Range = Cba_FonRange( p, OneFon ); + return Range == 1 ? OneFon : -1; + } +} void Cba_ManWriteFonRange( Cba_Ntk_t * p, int iFon ) { Vec_Str_t * vStr = &p->pDesign->vOut; - if ( Cba_FonIsConst(iFon) || Cba_FonRange(p, iFon) == 1 ) + if ( Cba_FonIsConst(iFon) || (Cba_FonRange(p, iFon) == 1 && Cba_FonRight(p, iFon) == 0) ) return; Vec_StrPush( vStr, '[' ); Vec_StrPrintNum( vStr, Cba_FonLeft(p, iFon) ); @@ -260,30 +302,59 @@ void Cba_ManWriteFonRange( Cba_Ntk_t * p, int iFon ) Vec_StrPush( vStr, ']' ); Vec_StrPush( vStr, ' ' ); } -void Cba_ManWriteFonName( Cba_Ntk_t * p, int iFon, int fInlineConcat ) +void Cba_ManWriteFonName( Cba_Ntk_t * p, int iFon, int fInlineConcat, int fInput ) { - extern void Cba_ManWriteConcat( Cba_Ntk_t * p, int iObj ); + extern void Cba_ManWriteCatIn( Cba_Ntk_t * p, int iObj ); Vec_Str_t * vStr = &p->pDesign->vOut; - if ( Cba_FonIsConst(iFon) ) - Vec_StrPrintStr( vStr, Cba_NtkConst(p, Cba_FonConst(iFon)) ); - else if ( fInlineConcat && Cba_ObjIsConcat(p, Cba_FonObj(p, iFon)) ) - Cba_ManWriteConcat( p, Cba_FonObj(p, iFon) ); + if ( !iFon || (!Cba_FonIsConst(iFon) && !Cba_FonName(p, iFon)) ) + { + Vec_StrPrintStr( vStr, "Open_" ); + Vec_StrPrintNum( vStr, Cba_NtkMan(p)->nOpens++ ); + return; + } + if ( fInlineConcat && !Cba_FonIsConst(iFon) && Cba_ObjIsCatIn(p, Cba_FonObj(p, iFon)) ) + Cba_ManWriteCatIn( p, Cba_FonObj(p, iFon) ); else - Vec_StrPrintStr( vStr, Cba_FonNameStr(p, iFon) ); + { + int Range = fInput ? Cba_FonRange( p, iFon ) : 0; + if ( fInput && Range > 1 ) + Vec_StrPush( vStr, '{' ); + if ( Cba_FonIsConst(iFon) ) + Vec_StrPrintStr( vStr, Cba_NtkConst(p, Cba_FonConst(iFon)) ); + else + Vec_StrPrintStr( vStr, Cba_FonNameStr(p, iFon) ); + if ( fInput && Range > 1 ) + Vec_StrPush( vStr, '}' ); + } } -void Cba_ManWriteConcat( Cba_Ntk_t * p, int iObj ) +void Cba_ManWriteCatIn( Cba_Ntk_t * p, int iObj ) { int i, iFin, iFon; Vec_Str_t * vStr = &p->pDesign->vOut; - assert( Cba_ObjIsConcat(p, iObj) ); + assert( Cba_ObjIsCatIn(p, iObj) ); Vec_StrPush( vStr, '{' ); Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) { Vec_StrPrintStr( vStr, i ? ", " : "" ); - Cba_ManWriteFonName( p, iFon, 1 ); + Cba_ManWriteFonName( p, iFon, 1, 0 ); } Vec_StrPush( vStr, '}' ); } +void Cba_ManWriteCatOut( Cba_Ntk_t * p, int iObj ) +{ + int i, iFon; + Vec_Str_t * vStr = &p->pDesign->vOut; + assert( Cba_ObjIsCatOut(p, iObj) ); + if ( Cba_ObjFonNum(p, iObj) > 1 ) + Vec_StrPush( vStr, '{' ); + Cba_ObjForEachFon( p, iObj, iFon, i ) + { + Vec_StrPrintStr( vStr, i ? ", " : "" ); + Cba_ManWriteFonName( p, iFon, 0, 0 ); + } + if ( Cba_ObjFonNum(p, iObj) > 1 ) + Vec_StrPush( vStr, '}' ); +} int Cba_ManWriteLineFile( Cba_Ntk_t * p, int iObj, int FileAttr, int LineAttr ) { Vec_Str_t * vStr = &p->pDesign->vOut; @@ -303,14 +374,14 @@ int Cba_ManWriteLineFile( Cba_Ntk_t * p, int iObj, int FileAttr, int LineAttr ) void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) { Vec_Str_t * vStr = &p->pDesign->vOut; - int i, iObj, iFin, iFon, StartPos, Status; + int i, k, iObj, iFin, iFon, StartPos, Status; int FileAttr = Cba_NtkStrId( p, "file" ); int LineAttr = Cba_NtkStrId( p, "line" ); int fUseNewLine = (int)(Cba_NtkPioNum(p) > 5); // mark PO fons Vec_Bit_t * vPoFons = Vec_BitStart( Cba_NtkFonNum(p)+1 ); Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) - if ( Cba_FonIsReal(iFon) ) + if ( Cba_FonIsReal(iFon) && Cba_FonName(p, iFon) == Cba_ObjName(p, iObj) ) Vec_BitWriteEntry( vPoFons, iFon, 1 ); // write header Vec_StrPrintStr( vStr, "module " ); @@ -333,11 +404,14 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) // write inputs/outputs Cba_NtkForEachPioOrder( p, iObj, i ) { + int Offset = Vec_StrSize(vStr); Vec_StrPrintStr( vStr, " " ); Vec_StrPrintStr( vStr, Cba_ObjIsPi(p, iObj) ? "input " : "output " ); Cba_ManWriteFonRange( p, Cba_ObjIsPi(p, iObj) ? Cba_ObjFon0(p, iObj) : Cba_ObjFinFon(p, iObj, 0) ); Vec_StrPrintStr( vStr, Cba_ObjNameStr(p, iObj) ); Vec_StrPush( vStr, ';' ); + for ( k = Vec_StrSize(vStr); k < Offset + 40; k++ ) + Vec_StrPush( vStr, ' ' ); Cba_ManWriteLineFile( p, iObj, FileAttr, LineAttr ); Vec_StrPush( vStr, '\n' ); } @@ -345,9 +419,10 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) // write objects Cba_NtkForEachBox( p, iObj ) { + int Type = Cba_ObjType(p, iObj); if ( Cba_ObjIsSlice(p, iObj) ) continue; - if ( fInlineConcat && Cba_ObjIsConcat(p, iObj) ) + if ( fInlineConcat && Cba_ObjIsCatIn(p, iObj) ) continue; if ( Cba_ObjIsBoxUser(p, iObj) ) { @@ -355,9 +430,11 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) // write output wire declarations Cba_ObjForEachFon( p, iObj, iFon, i ) { + if ( Vec_BitEntry(vPoFons, iFon) ) + continue; Vec_StrPrintStr( vStr, " wire " ); Cba_ManWriteFonRange( p, iFon ); - Cba_ManWriteFonName( p, iFon, 0 ); + Cba_ManWriteFonName( p, iFon, 0, 0 ); Vec_StrPrintStr( vStr, ";\n" ); } // write box @@ -375,7 +452,7 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) Vec_StrPush( vStr, '.' ); Vec_StrPrintStr( vStr, Cba_ObjNameStr(pNtk, Cba_NtkPi(pNtk, i)) ); Vec_StrPush( vStr, '(' ); - Cba_ManWriteFonName( p, iFon, fInlineConcat ); + Cba_ManWriteFonName( p, iFon, fInlineConcat, 1 ); Vec_StrPush( vStr, ')' ); } // write output binding @@ -385,63 +462,295 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) Vec_StrPush( vStr, '.' ); Vec_StrPrintStr( vStr, Cba_ObjNameStr(pNtk, Cba_NtkPo(pNtk, i)) ); Vec_StrPush( vStr, '(' ); - Cba_ManWriteFonName( p, iFon, 0 ); + Cba_ManWriteFonName( p, iFon, 0, 1 ); Vec_StrPush( vStr, ')' ); } Vec_StrPrintStr( vStr, ");" ); } - else + else if ( Type == CBA_BOX_CATOUT ) { - int Type = Cba_ObjType(p, iObj); - if ( Vec_BitEntry(vPoFons, Cba_ObjFon0(p, iObj)) ) + // write declarations + Cba_ObjForEachFon( p, iObj, iFon, i ) + { + if ( !Cba_FonName(p, iFon) ) + continue; + if ( Vec_BitEntry(vPoFons, iFon) ) + continue; + Vec_StrPrintStr( vStr, " wire " ); + Cba_ManWriteFonRange( p, iFon ); + Cba_ManWriteFonName( p, iFon, 0, 0 ); + Vec_StrPrintStr( vStr, ";\n" ); + } + // write output concatenation + Vec_StrPrintStr( vStr, " assign " ); + Cba_ManWriteCatOut( p, iObj ); + Vec_StrPrintStr( vStr, " = " ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), 0, 0 ); + Vec_StrPush( vStr, ';' ); + } + else if ( Type == CBA_BOX_NMUX || Type == CBA_BOX_SEL ) + { + int fUseSel = Type == CBA_BOX_SEL; + int nBits = fUseSel ? Cba_ObjFinNum(p, iObj) - 1 : Abc_Base2Log(Cba_ObjFinNum(p, iObj) - 1); + int iFonIn = Cba_ObjFinFon(p, iObj, 0); + int iFonOut = Cba_ObjFon0(p, iObj); + // function [15:0] res; + Vec_StrPrintStr( vStr, " function " ); + Cba_ManWriteFonRange( p, iFonOut ); + Vec_StrPrintStr( vStr, "_func_" ); + Cba_ManWriteFonName( p, iFonOut, 0, 0 ); + Vec_StrPrintStr( vStr, ";\n" ); + // input [1:0] s; + Vec_StrPrintStr( vStr, " input " ); + Cba_ManWriteFonRange( p, iFonIn ); + Vec_StrPrintStr( vStr, "s;\n" ); + // input [15:0] d0, d1, d2, d3; + Vec_StrPrintStr( vStr, " input " ); + Cba_ManWriteFonRange( p, iFonOut ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + { + if ( i == 0 ) continue; + Vec_StrPrintStr( vStr, i > 1 ? ", " : "" ); + Vec_StrPrintStr( vStr, "d" ); + Vec_StrPrintNum( vStr, i-1 ); + } + Vec_StrPrintStr( vStr, ";\n" ); + // casez (s) + Vec_StrPrintStr( vStr, " casez(s)" ); + if ( fUseSel ) + Vec_StrPrintStr( vStr, " // synopsys full_case parallel_case" ); + Vec_StrPrintStr( vStr, "\n" ); + // 2'b00: res = b[15:0]; + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + { + if ( i == 0 ) continue; + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintNum( vStr, nBits ); + Vec_StrPrintStr( vStr, "\'b" ); + if ( fUseSel ) + { + Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + nBits, '?' ); + Vec_StrWriteEntry( vStr, Vec_StrSize(vStr) - i, '1' ); + } + else + { + for ( k = nBits-1; k >= 0; k-- ) + Vec_StrPrintNum( vStr, ((i-1) >> k) & 1 ); + } + Vec_StrPrintStr( vStr, ": _func_" ); + Cba_ManWriteFonName( p, iFonOut, 0, 0 ); + Vec_StrPrintStr( vStr, " = " ); + Vec_StrPrintStr( vStr, "d" ); + Vec_StrPrintNum( vStr, i-1 ); + Vec_StrPrintStr( vStr, ";\n" ); + } + Vec_StrPrintStr( vStr, " endcase\n" ); + Vec_StrPrintStr( vStr, " endfunction\n" ); + // assign z = res(a, b, s); + if ( Vec_BitEntry(vPoFons, iFonOut) ) Vec_StrPrintStr( vStr, " assign " ); else { Vec_StrPrintStr( vStr, " wire " ); - Cba_ManWriteFonRange( p, Cba_ObjFon0(p, iObj) ); + Cba_ManWriteFonRange( p, iFonOut ); } - Cba_ManWriteFonName( p, Cba_ObjFon0(p, iObj), 0 ); - Vec_StrPrintStr( vStr, " = " ); - if ( Cba_ObjIsConcat(p, iObj) ) - Cba_ManWriteConcat( p, iObj ); - else if ( Type == CBA_BOX_MUX || Type == CBA_BOX_NMUX ) + Cba_ManWriteFonName( p, iFonOut, fInlineConcat, 0 ); + Vec_StrPrintStr( vStr, " = _func_" ); + Cba_ManWriteFonName( p, iFonOut, 0, 0 ); + Vec_StrPrintStr( vStr, " ( " ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) { - char * pSymb = Type == CBA_BOX_MUX ? " ? " : " ?? "; - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + Vec_StrPrintStr( vStr, i ? ", " : "" ); + Cba_ManWriteFonName( p, iFon, fInlineConcat, 0 ); + } + Vec_StrPrintStr( vStr, " );" ); + } + else if ( Type == CBA_BOX_DFFRS || Type == CBA_BOX_LATCHRS ) + { + int fUseFlop = Type == CBA_BOX_DFFRS; + int iFonQ = Cba_ObjFon0(p, iObj); + int iFonD = Cba_ObjFinFon(p, iObj, 0); + int iFonC = Cba_ObjFinFon(p, iObj, 3); + int iFonSet = Cba_ObjFindOne( p, Cba_ObjFinFon(p, iObj, 1) ); + int iFonRst = Cba_ObjFindOne( p, Cba_ObjFinFon(p, iObj, 2) ); + int Range = Cba_FonRange( p, iFonQ ); + if ( iFonSet < 0 || iFonRst < 0 ) + { + printf( "Cba_ManWriteVerilog(): In module \"%s\", cannot write object \"%s\".\n", Cba_NtkName(p), Cba_ObjNameStr(p, iObj) ); + continue; + } + assert( iFonSet >= 0 && iFonRst >= 0 ); + // reg [3:0] Q; + Vec_StrPrintStr( vStr, " reg " ); + Cba_ManWriteFonRange( p, iFonQ ); + Cba_ManWriteFonName( p, iFonQ, 0, 0 ); + Vec_StrPrintStr( vStr, ";\n" ); + // always @(posedge C or posedge PRE) + Vec_StrPrintStr( vStr, " always @(" ); + if ( fUseFlop ) + Vec_StrPrintStr( vStr, "posedge " ); + Cba_ManWriteFonName( p, iFonC, 0, 0 ); + if ( !fUseFlop ) + { + Vec_StrPrintStr( vStr, " or " ); + Cba_ManWriteFonName( p, iFonD, 0, 0 ); + } + if ( iFonSet > 0 ) + { + Vec_StrPrintStr( vStr, " or " ); + if ( fUseFlop ) + Vec_StrPrintStr( vStr, "posedge " ); + Cba_ManWriteFonName( p, iFonSet, 0, 0 ); + } + if ( iFonRst > 0 ) + { + Vec_StrPrintStr( vStr, " or " ); + if ( fUseFlop ) + Vec_StrPrintStr( vStr, "posedge " ); + Cba_ManWriteFonName( p, iFonRst, 0, 0 ); + } + Vec_StrPrintStr( vStr, ")\n" ); + // if (Set) Q <= 4'b1111; + if ( iFonSet ) + { + Vec_StrPrintStr( vStr, " if (" ); + Cba_ManWriteFonName( p, iFonSet, 0, 0 ); + Vec_StrPrintStr( vStr, ") " ); + Cba_ManWriteFonName( p, iFonQ, 0, 0 ); + Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " ); + Vec_StrPrintNum( vStr, Range ); + Vec_StrPrintStr( vStr, "\'b" ); + Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '1' ); + Vec_StrPrintStr( vStr, ";\n" ); + } + if ( iFonRst ) + { + Vec_StrPrintStr( vStr, iFonSet ? " else if (" : " if (" ); + Cba_ManWriteFonName( p, iFonRst, 0, 0 ); + Vec_StrPrintStr( vStr, ") " ); + Cba_ManWriteFonName( p, iFonQ, 0, 0 ); + Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " ); + Vec_StrPrintNum( vStr, Range ); + Vec_StrPrintStr( vStr, "\'b" ); + Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '0' ); + Vec_StrPrintStr( vStr, ";\n" ); + } + Vec_StrPrintStr( vStr, (iFonSet || iFonRst) ? " else " : " " ); + if ( !fUseFlop ) + { + Vec_StrPrintStr( vStr, " if (" ); + Cba_ManWriteFonName( p, iFonC, 0, 0 ); + Vec_StrPrintStr( vStr, ") " ); + } + Cba_ManWriteFonName( p, iFonQ, 0, 0 ); + Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " ); + Cba_ManWriteFonName( p, iFonD, fInlineConcat, 0 ); + Vec_StrPrintStr( vStr, ";" ); + } + else if ( Type == CBA_BOX_ADD ) + { + int iFon0 = Cba_ObjFon0(p, iObj); + int iFon1 = Cba_ObjFon(p, iObj, 1); + // write outputs + if ( Cba_FonName(p, iFon1) ) + { + if ( !Vec_BitEntry(vPoFons, iFon0) ) { - Vec_StrPrintStr( vStr, i ? (i == 1 ? pSymb: " : ") : "" ); - Cba_ManWriteFonName( p, iFon, fInlineConcat ); + Vec_StrPrintStr( vStr, " wire " ); + Cba_ManWriteFonRange( p, iFon0 ); + Cba_ManWriteFonName( p, iFon0, 0, 0 ); + Vec_StrPrintStr( vStr, ";\n" ); } + if ( !Vec_BitEntry(vPoFons, iFon1) ) + { + Vec_StrPrintStr( vStr, " wire " ); + Cba_ManWriteFonRange( p, iFon1 ); + Cba_ManWriteFonName( p, iFon1, 0, 0 ); + Vec_StrPrintStr( vStr, ";\n" ); + } + Vec_StrPrintStr( vStr, " assign {" ); + Cba_ManWriteFonName( p, iFon1, 0, 0 ); + Vec_StrPrintStr( vStr, ", " ); + Cba_ManWriteFonName( p, iFon0, 0, 0 ); + Vec_StrPrintStr( vStr, "} = " ); } - else if ( Type == CBA_BOX_SEL || Type == CBA_BOX_PSEL ) + else { - char * pSymb = Type == CBA_BOX_SEL ? " ?| " : " ?% "; - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + if ( Vec_BitEntry(vPoFons, iFon0) ) + Vec_StrPrintStr( vStr, " assign " ); + else { - Vec_StrPrintStr( vStr, i ? (i == 1 ? pSymb: " : ") : "" ); - Cba_ManWriteFonName( p, iFon, fInlineConcat ); + Vec_StrPrintStr( vStr, " wire " ); + Cba_ManWriteFonRange( p, iFon0 ); } + Cba_ManWriteFonName( p, iFon0, 0, 0 ); + Vec_StrPrintStr( vStr, " = " ); + } + // write carry-in + if ( Cba_ObjFinFon(p, iObj, 0) != Cba_FonFromConst(1) ) + { + Vec_StrPush( vStr, ' ' ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); + Vec_StrPush( vStr, ' ' ); + Vec_StrPrintStr( vStr, "+" ); + } + Vec_StrPush( vStr, ' ' ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); + Vec_StrPush( vStr, ' ' ); + Vec_StrPrintStr( vStr, "+" ); + Vec_StrPush( vStr, ' ' ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 2), fInlineConcat, 0 ); + Vec_StrPush( vStr, ';' ); + } + else + { + if ( Vec_BitEntry(vPoFons, Cba_ObjFon0(p, iObj)) ) + Vec_StrPrintStr( vStr, " assign " ); + else + { + Vec_StrPrintStr( vStr, " wire " ); + Cba_ManWriteFonRange( p, Cba_ObjFon0(p, iObj) ); + } + Cba_ManWriteFonName( p, Cba_ObjFon0(p, iObj), 0, 0 ); + Vec_StrPrintStr( vStr, " = " ); + if ( Cba_ObjIsCatIn(p, iObj) ) + Cba_ManWriteCatIn( p, iObj ); + else if ( Type == CBA_BOX_MUX ) + { + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); + Vec_StrPrintStr( vStr, " ? " ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); + Vec_StrPrintStr( vStr, " : " ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 2), fInlineConcat, 0 ); + } + else if ( Type == CBA_BOX_LTHAN ) + { + int fLessThan = (Cba_ObjFinFon(p, iObj, 0) == Cba_FonFromConst(1)); // const0 + Vec_StrPush( vStr, ' ' ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); + Vec_StrPush( vStr, ' ' ); + Vec_StrPrintStr( vStr, fLessThan ? "<" : "<=" ); + Vec_StrPush( vStr, ' ' ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 2), fInlineConcat, 0 ); } else if ( Cba_TypeIsUnary(Type) ) { Vec_StrPrintStr( vStr, Cba_NtkTypeName(p, Type) ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); } - else // binary operation + else if ( Cba_NtkTypeName(p, Type) ) // binary operation { Vec_StrPush( vStr, ' ' ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat ); + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); Vec_StrPush( vStr, ' ' ); Vec_StrPrintStr( vStr, Cba_NtkTypeName(p, Type) ); Vec_StrPush( vStr, ' ' ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat ); - if ( Type == CBA_BOX_ADD ) - { - Vec_StrPush( vStr, ' ' ); - Vec_StrPrintStr( vStr, Cba_NtkTypeName(p, Type) ); - Vec_StrPush( vStr, ' ' ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 2), fInlineConcat ); - } + Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); + } + else // unknown + { + Vec_StrPrintStr( vStr, "<unknown operator>" ); + printf( "Cba_ManWriteVerilog(): In module \"%s\", cannot write object \"%s\".\n", Cba_NtkName(p), Cba_ObjNameStr(p, iObj) ); } Vec_StrPush( vStr, ';' ); } @@ -465,7 +774,7 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) Vec_StrPrintStr( vStr, " assign " ); Vec_StrPrintStr( vStr, Cba_ObjNameStr(p, iObj) ); Vec_StrPrintStr( vStr, " = " ); - Cba_ManWriteFonName( p, iFon, fInlineConcat ); + Cba_ManWriteFonName( p, iFon, fInlineConcat, 0 ); Vec_StrPush( vStr, ';' ); Vec_StrPush( vStr, '\n' ); } @@ -484,6 +793,7 @@ void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p, int fInlineConcat ) } Cba_ManCreatePrimMap( p->pTypeNames ); // derive the stream + p->nOpens = 1; Vec_StrClear( &p->vOut ); Vec_StrClear( &p->vOut2 ); Vec_StrPrintStr( &p->vOut, "// Design \"" ); |