diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2015-03-01 19:11:15 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2015-03-01 19:11:15 -0800 |
commit | 2d90b916e6e46513786b7a0e38e8c0b7b938c623 (patch) | |
tree | ed0e3babe09b871779e0d4418dc1cef7541e2299 /src/base/cba | |
parent | f27979fc8fd5663d2bc9d9bad3fcbed2acfc4e17 (diff) | |
download | abc-2d90b916e6e46513786b7a0e38e8c0b7b938c623.tar.gz abc-2d90b916e6e46513786b7a0e38e8c0b7b938c623.tar.bz2 abc-2d90b916e6e46513786b7a0e38e8c0b7b938c623.zip |
Improvements to the CBA package.
Diffstat (limited to 'src/base/cba')
-rw-r--r-- | src/base/cba/cba.h | 229 | ||||
-rw-r--r-- | src/base/cba/cbaBlast.c | 2 | ||||
-rw-r--r-- | src/base/cba/cbaCba.c | 72 | ||||
-rw-r--r-- | src/base/cba/cbaCom.c | 20 | ||||
-rw-r--r-- | src/base/cba/cbaNtk.c | 359 | ||||
-rw-r--r-- | src/base/cba/cbaOper.c | 2 | ||||
-rw-r--r-- | src/base/cba/cbaPrsTrans.c | 93 | ||||
-rw-r--r-- | src/base/cba/cbaPtrAbc.c | 2 | ||||
-rw-r--r-- | src/base/cba/cbaReadVer.c | 142 | ||||
-rw-r--r-- | src/base/cba/cbaWriteBlif.c | 14 | ||||
-rw-r--r-- | src/base/cba/cbaWriteVer.c | 134 |
11 files changed, 647 insertions, 422 deletions
diff --git a/src/base/cba/cba.h b/src/base/cba/cba.h index d5802250..f00ecdfd 100644 --- a/src/base/cba/cba.h +++ b/src/base/cba/cba.h @@ -189,6 +189,8 @@ struct Cba_Man_t_ void * pMioLib; void ** ppGraphs; int ElemGates[4]; + char * pPrimNames[CBA_BOX_UNKNOWN]; + char * pPrimSymbs[CBA_BOX_UNKNOWN]; }; static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; } @@ -202,6 +204,8 @@ static inline Cba_Ntk_t * Cba_ManNtkFind( Cba_Man_t * p, char * pName ) { r static inline Cba_Ntk_t * Cba_ManRoot( Cba_Man_t * p ) { return Cba_ManNtk(p, p->iRoot); } static inline char * Cba_ManStr( Cba_Man_t * p, int i ) { return Abc_NamStr(p->pStrs, i); } static inline int Cba_ManStrId( Cba_Man_t * p, char * pStr ) { return Abc_NamStrFind(p->pStrs, pStr); } +static inline char * Cba_ManPrimName( Cba_Man_t * p, Cba_ObjType_t Type ) { return p->pPrimNames[Type]; } +static inline char * Cba_ManPrimSymb( Cba_Man_t * p, Cba_ObjType_t Type ) { return p->pPrimSymbs[Type]; } static inline int Cba_NtkId( Cba_Ntk_t * p ) { int i = p - p->pDesign->pNtks; assert(Cba_ManNtkIsOk(p->pDesign, i)); return i; } static inline Cba_Man_t * Cba_NtkMan( Cba_Ntk_t * p ) { return p->pDesign; } @@ -218,13 +222,13 @@ static inline int Cba_NtkPoNum( Cba_Ntk_t * p ) { r static inline int Cba_NtkPioNum( Cba_Ntk_t * p ) { return Cba_NtkPiNum(p) + Cba_NtkPoNum(p); } static inline int Cba_NtkPiNumAlloc( Cba_Ntk_t * p ) { return Vec_IntCap(&p->vInputs); } static inline int Cba_NtkPoNumAlloc( Cba_Ntk_t * p ) { return Vec_IntCap(&p->vOutputs); } -static inline int Cba_NtkBiNum( Cba_Ntk_t * p ) { return Vec_StrCountEntry(&p->vType, (char)CBA_OBJ_BI); } -static inline int Cba_NtkBoNum( Cba_Ntk_t * p ) { return Vec_StrCountEntry(&p->vType, (char)CBA_OBJ_BO); } +static inline int Cba_NtkBiNum( Cba_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)CBA_OBJ_BI); } +static inline int Cba_NtkBoNum( Cba_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)CBA_OBJ_BO); } static inline int Cba_NtkCiNum( Cba_Ntk_t * p ) { return Cba_NtkPiNum(p) + Cba_NtkBoNum(p); } static inline int Cba_NtkCoNum( Cba_Ntk_t * p ) { return Cba_NtkPoNum(p) + Cba_NtkBiNum(p); } -static inline int Cba_NtkBoxNum( Cba_Ntk_t * p ) { return Cba_NtkObjNum(p) - Vec_StrCountSmaller(&p->vType, (char)CBA_OBJ_BOX); } -static inline int Cba_NtkPrimNum( Cba_Ntk_t * p ) { return Vec_StrCountLarger(&p->vType, (char)CBA_OBJ_BOX); } -static inline int Cba_NtkUserNum( Cba_Ntk_t * p ) { return Vec_StrCountEntry(&p->vType, (char)CBA_OBJ_BOX); } +static inline int Cba_NtkBoxNum( Cba_Ntk_t * p ) { return Cba_NtkObjNum(p) - Vec_StrCountSmallerLit(&p->vType, (char)CBA_OBJ_BOX); } +static inline int Cba_NtkPrimNum( Cba_Ntk_t * p ) { return Vec_StrCountLargerLit(&p->vType, (char)CBA_OBJ_BOX); } +static inline int Cba_NtkUserNum( Cba_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)CBA_OBJ_BOX); } static inline int Cba_NtkPi( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInputs, i); } static inline int Cba_NtkPo( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vOutputs, i); } @@ -257,8 +261,9 @@ static inline int Cba_NtkHasCopies( Cba_Ntk_t * p ) { r static inline int Cba_TypeIsBox( Cba_ObjType_t Type ) { return Type >= CBA_OBJ_BOX && Type < CBA_BOX_UNKNOWN; } static inline Cba_NameType_t Cba_NameType( int n ) { assert( n ); return (Cba_NameType_t)Abc_Lit2Att2( n ); } +static inline int Cba_CharIsDigit( char c ) { return c >= '0' && c <= '9'; } -static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return (Cba_ObjType_t)Vec_StrEntry(&p->vType, i); } +static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return (Cba_ObjType_t)Abc_Lit2Var((int)(unsigned char)Vec_StrEntry(&p->vType, i)); } static inline int Cba_ObjIsPi( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PI; } static inline int Cba_ObjIsPo( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PO; } static inline int Cba_ObjIsPio( Cba_Ntk_t * p, int i ) { return Cba_ObjIsPi(p, i) || Cba_ObjIsPo(p, i); } @@ -275,6 +280,8 @@ static inline int Cba_ObjIsCio( Cba_Ntk_t * p, int i ) { r static inline int Cba_ObjIsConst( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) >= CBA_BOX_CF && Cba_ObjType(p, i) <= CBA_BOX_CZ; } static inline int Cba_ObjIsConstBin( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_BOX_CF || Cba_ObjType(p, i) == CBA_BOX_CT; } +static inline int Cba_ObjBit( Cba_Ntk_t * p, int i ) { assert(!Cba_ObjIsBox(p, i)); return Abc_LitIsCompl((int)Vec_StrEntry(&p->vType, i)); } +static inline void Cba_ObjSetBit( Cba_Ntk_t * p, int i ) { char *q = Vec_StrArray(&p->vType); assert(!Cba_ObjIsBox(p, i)); q[i] = (char)Abc_LitNot((int)q[i]); } static inline int Cba_ObjFanin( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsCo(p, i)); return Vec_IntEntry(&p->vFanin, i); } static inline int Cba_ObjIndex( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsCio(p, i)); return Vec_IntEntry(&p->vIndex, i); } static inline int Cba_ObjNameInt( Cba_Ntk_t * p, int i ) { assert(!Cba_ObjIsCo(p, i)); return Vec_IntEntry(&p->vName, i); } @@ -303,6 +310,9 @@ static inline int Cba_BoxBiBox( Cba_Ntk_t * p, int i ) { a static inline int Cba_BoxBoBox( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBo(p, i)); return i - 1 - Cba_ObjIndex(p, i); } static inline int Cba_BoxFanin( Cba_Ntk_t * p, int b, int i ) { return Cba_ObjFanin(p, Cba_BoxBi(p, b, i)); } static inline int Cba_BoxFaninBox( Cba_Ntk_t * p, int b, int i ) { return Cba_BoxBoBox(p, Cba_BoxFanin(p, b, i)); } +static inline int Cba_BoxBiRange( Cba_Ntk_t * p, int i ) { int s = i; assert(Cba_ObjIsBi(p, i) && !Cba_ObjBit(p, i)); while (--i >= 0 && Cba_ObjIsBi(p, i) && Cba_ObjBit(p, i)) {} return s - i; } +static inline int Cba_BoxBoRange( Cba_Ntk_t * p, int i ) { int s = i; assert(Cba_ObjIsBo(p, i) && !Cba_ObjBit(p, i)); while (++i < Cba_NtkObjNum(p) && Cba_ObjIsBo(p, i) && Cba_ObjBit(p, i)) {} return i - s; } +static inline int Cba_ObjPiRange( Cba_Ntk_t * p, int i ) { int s = i; assert(Cba_ObjIsPi(p, i) && !Cba_ObjBit(p, i)); while (++i < Cba_NtkObjNum(p) && Cba_ObjIsPi(p, i) && Cba_ObjBit(p, i)) {} return i - s; } static inline int Cba_BoxNtkId( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Vec_IntEntry(&p->vFanin, i); } static inline void Cba_BoxSetNtkId( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjIsBox(p, i)&&Cba_ManNtkIsOk(p->pDesign, x));Vec_IntSetEntry(&p->vFanin, i, x);} @@ -313,110 +323,6 @@ static inline Cba_Ntk_t * Cba_BoxBiNtk( Cba_Ntk_t * p, int i ) { r static inline Cba_Ntk_t * Cba_BoxBoNtk( Cba_Ntk_t * p, int i ) { return Cba_ManNtk( p->pDesign, Cba_BoxBoNtkId(p, i) ); } static inline char * Cba_BoxNtkName( Cba_Ntk_t * p, int i ) { return Abc_NamStr( p->pDesign->pMods, Cba_BoxNtkId(p, i) ); } -static inline int Cba_CharIsDigit( char c ) { return c >= '0' && c <= '9'; } -static inline int Cba_NtkNamePoNum( char * pName ) -{ - int Multi = 1, Counter = 0; - char * pTemp = pName + strlen(pName) - 1; - assert( Cba_CharIsDigit(*pTemp) ); - for ( ; pName < pTemp && Cba_CharIsDigit(*pTemp); pTemp--, Multi *= 10 ) - Counter += Multi * (*pTemp - '0'); - return Counter; -} -static inline int Cba_NtkNamePiNum( char * pName ) -{ - char * pTemp; int CounterAll = 0, Counter = 0; - for ( pTemp = pName; *pTemp; pTemp++ ) - { - if ( Cba_CharIsDigit(*pTemp) ) - Counter = 10 * Counter + *pTemp - '0'; - else - CounterAll += Counter, Counter = 0; - } - return CounterAll; -} -static inline int Cba_NtkNameRanges( char * pName, int * pRanges, char * pSymbs ) -{ - char Symb, * pTemp; - int nSigs = 0, Num = 0; - assert( !strncmp(pName, "ABC", 3) ); - for ( pTemp = pName; *pTemp && !Cba_CharIsDigit(*pTemp); pTemp++ ); - assert( Cba_CharIsDigit(*pTemp) ); - Symb = *(pTemp - 1); - for ( ; *pTemp; pTemp++ ) - { - if ( Cba_CharIsDigit(*pTemp) ) - Num = 10 * Num + *pTemp - '0'; - else - pSymbs[nSigs] = Symb, Symb = *pTemp, pRanges[nSigs++] = Num, Num = 0; - } - assert( Num > 0 ); - pSymbs[nSigs] = Symb, pRanges[nSigs++] = Num; - return nSigs; -} -static inline int Cba_NtkReadRangesPrim( char * pName, Vec_Int_t * vRanges, int fPo ) -{ - char * pTemp; int Last, Num = 0, Count = 0; - assert( !strncmp(pName, "ABC", 3) ); - for ( pTemp = pName; *pTemp && !Cba_CharIsDigit(*pTemp); pTemp++ ); - assert( Cba_CharIsDigit(*pTemp) ); - Vec_IntClear( vRanges ); - for ( ; *pTemp; pTemp++ ) - { - if ( Cba_CharIsDigit(*pTemp) ) - Num = 10 * Num + *pTemp - '0'; - else - Vec_IntPush( vRanges, Num ), Count += Num, Num = 0; - } - assert( Num > 0 ); - Vec_IntPush( vRanges, Num ); Count += Num; - Last = Vec_IntPop(vRanges); - if ( !fPo ) - return Count; - if ( !strncmp(pName, "ABCADD", 6) ) - Vec_IntFillTwo( vRanges, 2, Last - 1, 1 ); - else - Vec_IntFill( vRanges, 1, Last ); - return Vec_IntSum(vRanges); -} -static inline int Cba_NtkReadRangesUser( Cba_Ntk_t * p, Vec_Int_t * vRanges, int fPo ) -{ - int Count = 0; - assert( fPo == 0 || fPo == 1 ); - if ( Cba_NtkInfoNum(p) == 0 ) - { - if ( vRanges ) - Vec_IntFill( vRanges, fPo ? Cba_NtkPoNum(p) : Cba_NtkPiNum(p), 1 ); - Count = fPo ? Cba_NtkPoNum(p) : Cba_NtkPiNum(p); - } - else - { - int Value, Beg, End, k; - if ( vRanges ) - Vec_IntClear( vRanges ); - Vec_IntForEachEntryTriple( &p->vInfo, Value, Beg, End, k ) - if ( Abc_Lit2Att2(Value) == (fPo ? 2 : 1) ) - { - if ( vRanges ) - Vec_IntPush( vRanges, Cba_InfoRange(Beg, End) ); - Count += Cba_InfoRange(Beg, End); - } - } - return Count; -} -static inline int Cba_ObjGetRange( Cba_Ntk_t * p, int iObj ) -{ - int i, NameId = Cba_ObjName(p, iObj); - assert( Cba_ObjIsCi(p, iObj) ); -// if ( Cba_NameType(NameId) == CBA_NAME_INDEX ) -// NameId = Cba_ObjName(p, iObj - Abc_Lit2Var2(NameId)); - assert( Cba_NameType(NameId) == CBA_NAME_WORD || Cba_NameType(NameId) == CBA_NAME_INFO ); - for ( i = iObj + 1; i < Cba_NtkObjNum(p); i++ ) - if ( !Cba_ObjIsCi(p, i) || Cba_ObjNameType(p, i) != CBA_NAME_INDEX ) - break; - return i - iObj; -} - //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -432,9 +338,14 @@ static inline int Cba_ObjGetRange( Cba_Ntk_t * p, int iObj ) for ( i = 0; (i < Cba_NtkPiNum(p)) && (((iObj) = Cba_NtkPi(p, i)), 1); i++ ) #define Cba_NtkForEachPo( p, iObj, i ) \ for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Cba_NtkPo(p, i)), 1); i++ ) -#define Cba_NtkForEachPoDriver( p, iObj, i ) \ +#define Cba_NtkForEachPoDriver( p, iObj, i ) \ for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Cba_ObjFanin(p, Cba_NtkPo(p, i))), 1); i++ ) +#define Cba_NtkForEachPiMain( p, iObj, i ) \ + for ( i = 0; (i < Cba_NtkPiNum(p)) && (((iObj) = Cba_NtkPi(p, i)), 1); i++ ) if ( Cba_ObjBit(p, iObj) ) {} else +#define Cba_NtkForEachPoMain( p, iObj, i ) \ + for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Cba_NtkPo(p, i)), 1); i++ ) if ( Cba_ObjBit(p, iObj) ) {} else + #define Cba_NtkForEachObj( p, i ) if ( !Cba_ObjType(p, i) ) {} else \ for ( i = 0; (i < Cba_NtkObjNum(p)); i++ ) #define Cba_NtkForEachObjType( p, Type, i ) \ @@ -468,6 +379,11 @@ static inline int Cba_ObjGetRange( Cba_Ntk_t * p, int iObj ) #define Cba_BoxForEachBiReverse( p, iBox, iTerm, i ) \ for ( i = Cba_BoxBiNum(p, iBox), iTerm = iBox - i--; Cba_ObjIsBi(p, iTerm); iTerm++, i-- ) +#define Cba_BoxForEachBiMain( p, iBox, iTerm, i ) \ + for ( iTerm = iBox - 1, i = 0; iTerm >= 0 && Cba_ObjIsBi(p, iTerm); iTerm--, i++ ) if ( Cba_ObjBit(p, iTerm) ) {} else +#define Cba_BoxForEachBoMain( p, iBox, iTerm, i ) \ + for ( iTerm = iBox + 1, i = 0; iTerm < Cba_NtkObjNum(p) && Cba_ObjIsBo(p, iTerm); iTerm++, i++ ) if ( Cba_ObjBit(p, iTerm) ) {} else + #define Cba_BoxForEachFanin( p, iBox, iFanin, i ) \ for ( i = 0; iBox - 1 - i >= 0 && Cba_ObjIsBi(p, iBox - 1 - i) && (((iFanin) = Cba_BoxFanin(p, iBox, i)), 1); i++ ) #define Cba_BoxForEachFaninBox( p, iBox, iFanin, i ) \ @@ -501,7 +417,7 @@ static inline int Cba_ObjAlloc( Cba_Ntk_t * p, Cba_ObjType_t Type, int Fanin ) Vec_IntPush( &p->vInputs, iObj ); else if ( Type == CBA_OBJ_PO ) Vec_IntPush( &p->vOutputs, iObj ); - Vec_StrPush( &p->vType, (char)Type ); + Vec_StrPush( &p->vType, (char)Abc_Var2Lit(Type, 0) ); Vec_IntPush( &p->vFanin, Fanin ); return iObj; } @@ -561,6 +477,26 @@ static inline void Cba_BoxReplace( Cba_Ntk_t * p, int iBox, int * pArray, int nS } +static inline Vec_Int_t * Cba_BoxCollectRanges( Cba_Ntk_t * p, int iBox ) +{ + static Vec_Int_t Bits, * vBits = &Bits; + static int pArray[10]; int i, iTerm; + assert( !Cba_ObjIsBoxUser(p, iBox) ); + // initialize array + vBits->pArray = pArray; + vBits->nSize = 0; + vBits->nCap = 10; + // iterate through inputs + Cba_BoxForEachBiMain( p, iBox, iTerm, i ) + Vec_IntPush( vBits, Cba_BoxBiRange(p, iTerm) ); + // iterate through outputs + Cba_BoxForEachBoMain( p, iBox, iTerm, i ) + Vec_IntPush( vBits, Cba_BoxBoRange(p, iTerm) ); + assert( Vec_IntSize(vBits) < 10 ); + //Vec_IntPrint( vBits ); + return vBits; +} + /**Function************************************************************* Synopsis [Prints vector.] @@ -782,6 +718,7 @@ static inline void Cba_NtkPrint( Cba_Ntk_t * p ) ***********************************************************************/ static inline Cba_Man_t * Cba_ManAlloc( char * pFileName, int nNtks ) { + extern void Cba_ManSetupTypes( char ** pNames, char ** pSymbs ); Cba_Ntk_t * pNtk; int i; Cba_Man_t * pNew = ABC_CALLOC( Cba_Man_t, 1 ); pNew->pName = Extra_FileDesignName( pFileName ); @@ -793,6 +730,7 @@ static inline Cba_Man_t * Cba_ManAlloc( char * pFileName, int nNtks ) pNew->pNtks = ABC_CALLOC( Cba_Ntk_t, pNew->nNtks ); Cba_ManForEachNtk( pNew, pNtk, i ) pNtk->pDesign = pNew; + Cba_ManSetupTypes( pNew->pPrimNames, pNew->pPrimSymbs ); return pNew; } static inline Cba_Man_t * Cba_ManStart( Cba_Man_t * p, int nNtks ) @@ -956,6 +894,7 @@ static inline Cba_ObjType_t Ptr_SopToType( char * pSop ) if ( !strcmp(pSop, "11 1\n00 1\n") ) return CBA_BOX_XNOR; if ( !strcmp(pSop, "00 1\n11 1\n") ) return CBA_BOX_XNOR; if ( !strcmp(pSop, "10 1\n") ) return CBA_BOX_SHARP; + if ( !strcmp(pSop, "01 1\n") ) return CBA_BOX_SHARPL; assert( 0 ); return CBA_OBJ_NONE; } @@ -975,6 +914,7 @@ static inline char * Ptr_SopToTypeName( char * pSop ) if ( !strcmp(pSop, "11 1\n00 1\n") ) return "CBA_BOX_XNOR"; if ( !strcmp(pSop, "00 1\n11 1\n") ) return "CBA_BOX_XNOR"; if ( !strcmp(pSop, "10 1\n") ) return "CBA_BOX_SHARP"; + if ( !strcmp(pSop, "01 1\n") ) return "CBA_BOX_SHARPL"; assert( 0 ); return NULL; } @@ -982,6 +922,8 @@ static inline char * Ptr_TypeToName( Cba_ObjType_t Type ) { if ( Type == CBA_BOX_CF ) return "const0"; if ( Type == CBA_BOX_CT ) return "const1"; + if ( Type == CBA_BOX_CX ) return "constX"; + if ( Type == CBA_BOX_CZ ) return "constZ"; if ( Type == CBA_BOX_BUF ) return "buf"; if ( Type == CBA_BOX_INV ) return "not"; if ( Type == CBA_BOX_AND ) return "and"; @@ -993,6 +935,7 @@ static inline char * Ptr_TypeToName( Cba_ObjType_t Type ) if ( Type == CBA_BOX_MUX ) return "mux"; if ( Type == CBA_BOX_MAJ ) return "maj"; if ( Type == CBA_BOX_SHARP ) return "sharp"; + if ( Type == CBA_BOX_SHARPL) return "sharpl"; assert( 0 ); return "???"; } @@ -1000,6 +943,8 @@ static inline char * Ptr_TypeToSop( Cba_ObjType_t Type ) { if ( Type == CBA_BOX_CF ) return " 0\n"; if ( Type == CBA_BOX_CT ) return " 1\n"; + if ( Type == CBA_BOX_CX ) return " 0\n"; + if ( Type == CBA_BOX_CZ ) return " 0\n"; if ( Type == CBA_BOX_BUF ) return "1 1\n"; if ( Type == CBA_BOX_INV ) return "0 1\n"; if ( Type == CBA_BOX_AND ) return "11 1\n"; @@ -1009,6 +954,7 @@ static inline char * Ptr_TypeToSop( Cba_ObjType_t Type ) if ( Type == CBA_BOX_XOR ) return "01 1\n10 1\n"; if ( Type == CBA_BOX_XNOR ) return "00 1\n11 1\n"; if ( Type == CBA_BOX_SHARP ) return "10 1\n"; + if ( Type == CBA_BOX_SHARPL) return "01 1\n"; if ( Type == CBA_BOX_MUX ) return "11- 1\n0-1 1\n"; if ( Type == CBA_BOX_MAJ ) return "11- 1\n1-1 1\n-11 1\n"; assert( 0 ); @@ -1016,46 +962,49 @@ static inline char * Ptr_TypeToSop( Cba_ObjType_t Type ) } /*=== cbaCom.c ===============================================================*/ -extern void Abc_FrameImportPtr( Vec_Ptr_t * vPtr ); -extern Vec_Ptr_t * Abc_FrameExportPtr(); +extern void Abc_FrameImportPtr( Vec_Ptr_t * vPtr ); +extern Vec_Ptr_t * Abc_FrameExportPtr(); /*=== cbaBlast.c =============================================================*/ -extern int Cba_NtkBuildLibrary( Cba_Man_t * p ); -extern Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose ); -extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ); -extern void * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc ); +extern int Cba_NtkBuildLibrary( Cba_Man_t * p ); +extern Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose ); +extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ); +extern void * 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 ); +extern Cba_Man_t * Cba_ManReadCba( char * pFileName ); +extern void Cba_ManWriteCba( char * pFileName, Cba_Man_t * p ); /*=== cbaNtk.c ===============================================================*/ -extern void Cba_NtkUpdateFanout( Cba_Ntk_t * p, int iOld, int iNew ); -extern void Cba_ManDeriveFanout( Cba_Man_t * p ); -extern void Cba_ManAssignInternNames( Cba_Man_t * p ); -extern void Cba_ManAssignInternWordNames( Cba_Man_t * p ); -extern Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p ); +extern char * Cba_NtkGenerateName( Cba_Ntk_t * p, Cba_ObjType_t Type, Vec_Int_t * vBits ); +extern Cba_ObjType_t Cba_NameToType( char * pName ); +extern Vec_Int_t * Cba_NameToRanges( char * pName ); +extern void Cba_NtkUpdateFanout( Cba_Ntk_t * p, int iOld, int iNew ); +extern void Cba_ManDeriveFanout( Cba_Man_t * p ); +//extern void Cba_ManAssignInternNames( Cba_Man_t * p ); +extern void Cba_ManAssignInternWordNames( Cba_Man_t * p ); +extern Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p ); /*=== cbaPtr.c ===============================================================*/ -extern void Cba_PtrFree( Vec_Ptr_t * vDes ); -extern int Cba_PtrMemory( Vec_Ptr_t * vDes ); -extern void Cba_PtrDumpBlif( char * pFileName, Vec_Ptr_t * vDes ); -extern Vec_Ptr_t * Cba_PtrTransformTest( Vec_Ptr_t * vDes ); +extern void Cba_PtrFree( Vec_Ptr_t * vDes ); +extern int Cba_PtrMemory( Vec_Ptr_t * vDes ); +extern void Cba_PtrDumpBlif( char * pFileName, Vec_Ptr_t * vDes ); +extern Vec_Ptr_t * Cba_PtrTransformTest( Vec_Ptr_t * vDes ); /*=== cbaPtrAbc.c ============================================================*/ -extern Cba_Man_t * Cba_PtrTransformToCba( Vec_Ptr_t * vDes ); -extern Vec_Ptr_t * Cba_PtrDeriveFromCba( Cba_Man_t * p ); +extern Cba_Man_t * Cba_PtrTransformToCba( Vec_Ptr_t * vDes ); +extern Vec_Ptr_t * Cba_PtrDeriveFromCba( Cba_Man_t * p ); /*=== cbaPrsBuild.c ==========================================================*/ -extern void Prs_ManVecFree( Vec_Ptr_t * vPrs ); -extern Cba_Man_t * Prs_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes ); +extern void Prs_ManVecFree( Vec_Ptr_t * vPrs ); +extern Cba_Man_t * Prs_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes ); /*=== cbaReadBlif.c ==========================================================*/ -extern Vec_Ptr_t * Prs_ManReadBlif( char * pFileName ); +extern Vec_Ptr_t * Prs_ManReadBlif( char * pFileName ); /*=== cbaReadSmt.c ===========================================================*/ -extern Vec_Ptr_t * Prs_ManReadSmt( char * pFileName ); +extern Vec_Ptr_t * Prs_ManReadSmt( char * pFileName ); /*=== cbaReadVer.c ===========================================================*/ -extern Vec_Ptr_t * Prs_ManReadVerilog( char * pFileName ); +extern Vec_Ptr_t * Prs_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 ); +extern void Prs_ManWriteVerilog( char * pFileName, Vec_Ptr_t * p ); +extern void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p, int fUseAssign ); ABC_NAMESPACE_HEADER_END diff --git a/src/base/cba/cbaBlast.c b/src/base/cba/cbaBlast.c index 15e433fc..e4b3fc1a 100644 --- a/src/base/cba/cbaBlast.c +++ b/src/base/cba/cbaBlast.c @@ -300,7 +300,7 @@ void Cba_ManMarkNodesGia( Cba_Man_t * p, Gia_Man_t * pGia ) void Cba_ManRemapBarbufs( Cba_Man_t * pNew, Cba_Man_t * p ) { Cba_Ntk_t * pNtk; int Entry, i; - assert( Vec_IntSize(&p->vBuf2RootNtk) ); + //assert( Vec_IntSize(&p->vBuf2RootNtk) ); assert( !Vec_IntSize(&pNew->vBuf2RootNtk) ); Vec_IntAppend( &pNew->vBuf2RootNtk, &p->vBuf2RootNtk ); Vec_IntAppend( &pNew->vBuf2RootObj, &p->vBuf2RootObj ); diff --git a/src/base/cba/cbaCba.c b/src/base/cba/cbaCba.c index d7bcb562..3a759ab8 100644 --- a/src/base/cba/cbaCba.c +++ b/src/base/cba/cbaCba.c @@ -102,6 +102,7 @@ void Cba_ManReadCbaVecInt( Vec_Str_t * vOut, int * pPos, Vec_Int_t * p, int nSiz void Cba_ManReadCbaNtk( Vec_Str_t * vOut, int * pPos, Cba_Ntk_t * pNtk ) { int i, Type; + //char * pName; int iObj, NameId; Cba_ManReadCbaVecStr( vOut, pPos, &pNtk->vType, Cba_NtkObjNumAlloc(pNtk) ); Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vFanin, 4 * Cba_NtkObjNumAlloc(pNtk) ); Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vInfo, 12 * Cba_NtkInfoNumAlloc(pNtk) ); @@ -116,20 +117,41 @@ void Cba_ManReadCbaNtk( Vec_Str_t * vOut, int * pPos, Cba_Ntk_t * pNtk ) assert( Cba_NtkPoNum(pNtk) == Cba_NtkPoNumAlloc(pNtk) ); assert( Cba_NtkObjNum(pNtk) == Cba_NtkObjNumAlloc(pNtk) ); assert( Cba_NtkInfoNum(pNtk) == Cba_NtkInfoNumAlloc(pNtk) ); +/* + // read input/output/box names + Cba_NtkForEachPiMain( pNtk, iObj, i ) + { + pName = Vec_StrEntryP( vOut, Pos ); + NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); + Pos += strlen(pName) + 1; + } + Cba_NtkForEachPoMain( pNtk, iObj, i ) + { + pName = Vec_StrEntryP( vOut, Pos ); + NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); + Pos += strlen(pName) + 1; + } + Cba_NtkForEachBox( pNtk, iObj ) + { + pName = Vec_StrEntryP( vOut, Pos ); + NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); + Pos += strlen(pName) + 1; + } +*/ } Cba_Man_t * Cba_ManReadCbaInt( Vec_Str_t * vOut ) { Cba_Man_t * p; Cba_Ntk_t * pNtk; char Buffer[1000] = "#"; - int i, NameId, Pos = 0, nNtks, nPrims, Num1, Num2, Num3, Num4; + int i, NameId, Pos = 0, nNtks, Num1, Num2, Num3, Num4; while ( Buffer[0] == '#' ) if ( !CbaManReadCbaLine(vOut, &Pos, Buffer, Buffer+1000) ) return NULL; - if ( !CbaManReadCbaNameAndNums(Buffer, &nNtks, &nPrims, &Num3, &Num4) ) + if ( !CbaManReadCbaNameAndNums(Buffer, &nNtks, &Num2, &Num3, &Num4) ) return NULL; // start manager - assert( nNtks > 0 && nPrims > 0 ); + assert( nNtks > 0 ); p = Cba_ManAlloc( Buffer, nNtks ); // start networks Cba_ManForEachNtk( p, pNtk, i ) @@ -152,16 +174,8 @@ Cba_Man_t * Cba_ManReadCbaInt( Vec_Str_t * vOut ) // read networks Cba_ManForEachNtk( p, pNtk, i ) Cba_ManReadCbaNtk( vOut, &Pos, pNtk ); - // read primitives - for ( i = 0; i < nPrims; i++ ) - { - char * pName = Vec_StrEntryP( vOut, Pos ); - Abc_NamStrFindOrAdd( p->pMods, pName, NULL ); - Pos += strlen(pName) + 1; - } - assert( Pos == Vec_StrSize(vOut) ); assert( Cba_ManNtkNum(p) == nNtks ); - assert( Cba_ManPrimNum(p) == nPrims ); + assert( Pos == Vec_StrSize(vOut) ); return p; } Cba_Man_t * Cba_ManReadCba( char * pFileName ) @@ -187,7 +201,7 @@ Cba_Man_t * Cba_ManReadCba( char * pFileName ) nFileSize = fread( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile ); assert( nFileSize == Vec_StrSize(vOut) ); fclose( pFile ); - // read the library + // read the networks p = Cba_ManReadCbaInt( vOut ); if ( p != NULL ) { @@ -211,18 +225,40 @@ Cba_Man_t * Cba_ManReadCba( char * pFileName ) ***********************************************************************/ void Cba_ManWriteCbaNtk( Vec_Str_t * vOut, Cba_Ntk_t * pNtk ) { + //char * pName; int iObj, NameId; Vec_StrPushBuffer( vOut, (char *)Vec_StrArray(&pNtk->vType), Cba_NtkObjNum(pNtk) ); Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vFanin), 4 * Cba_NtkObjNum(pNtk) ); Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vInfo), 12 * Cba_NtkInfoNum(pNtk) ); +/* + // write input/output/box names + Cba_NtkForEachPiMain( pNtk, iObj, i ) + { + pName = Cba_ObjNameStr( pNtk, iObj ); + Vec_StrPrintStr( vOut, pName ); + Vec_StrPush( vOut, '\0' ); + } + Cba_NtkForEachPoMain( pNtk, iObj, i ) + { + pName = Cba_ObjNameStr( pNtk, iObj ); + Vec_StrPrintStr( vOut, pName ); + Vec_StrPush( vOut, '\0' ); + } + Cba_NtkForEachBox( pNtk, iObj ) + { + pName = Cba_ObjNameStr( pNtk, iObj ); + Vec_StrPrintStr( vOut, pName ); + Vec_StrPush( vOut, '\0' ); + } +*/ } void Cba_ManWriteCbaInt( Vec_Str_t * vOut, Cba_Man_t * p ) { char Buffer[1000]; - Cba_Ntk_t * pNtk; int i, nPrims = Cba_ManPrimNum(p); + Cba_Ntk_t * pNtk; int i; sprintf( Buffer, "# Design \"%s\" written by ABC on %s\n", Cba_ManName(p), Extra_TimeStamp() ); Vec_StrPrintStr( vOut, Buffer ); // write short info - sprintf( Buffer, "%s %d %d \n", Cba_ManName(p), Cba_ManNtkNum(p), Cba_ManPrimNum(p) ); + sprintf( Buffer, "%s %d \n", Cba_ManName(p), Cba_ManNtkNum(p) ); Vec_StrPrintStr( vOut, Buffer ); Cba_ManForEachNtk( p, pNtk, i ) { @@ -232,12 +268,6 @@ void Cba_ManWriteCbaInt( Vec_Str_t * vOut, Cba_Man_t * p ) } Cba_ManForEachNtk( p, pNtk, i ) Cba_ManWriteCbaNtk( vOut, pNtk ); - for ( i = 0; i < nPrims; i++ ) - { - char * pName = Abc_NamStr( p->pMods, Cba_ManNtkNum(p) + i ); - Vec_StrPrintStr( vOut, pName ); - Vec_StrPush( vOut, '\0' ); - } } void Cba_ManWriteCba( char * pFileName, Cba_Man_t * p ) { diff --git a/src/base/cba/cbaCom.c b/src/base/cba/cbaCom.c index a3efe3b0..f587b96d 100644 --- a/src/base/cba/cbaCom.c +++ b/src/base/cba/cbaCom.c @@ -198,21 +198,24 @@ int Cba_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) vDes = Prs_ManReadBlif( pFileName ); if ( vDes && Vec_PtrSize(vDes) ) p = Prs_ManBuildCba( pFileName, vDes ); - Prs_ManVecFree( vDes ); + if ( vDes ) + Prs_ManVecFree( vDes ); } else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) { vDes = Prs_ManReadVerilog( pFileName ); if ( vDes && Vec_PtrSize(vDes) ) p = Prs_ManBuildCba( pFileName, vDes ); - Prs_ManVecFree( 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 ); - Prs_ManVecFree( vDes ); + if ( vDes ) + Prs_ManVecFree( vDes ); } else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) { @@ -249,12 +252,16 @@ 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 c, fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "avh" ) ) != EOF ) { switch ( c ) { + case 'a': + fUseAssign ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -282,7 +289,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" ) ) - Cba_ManWriteVerilog( pFileName, p ); + Cba_ManWriteVerilog( pFileName, p, fUseAssign ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) Cba_ManWriteCba( pFileName, p ); else @@ -292,8 +299,9 @@ int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) } return 0; usage: - Abc_Print( -2, "usage: @write [-vh]\n" ); + Abc_Print( -2, "usage: @write [-avh]\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-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1; diff --git a/src/base/cba/cbaNtk.c b/src/base/cba/cbaNtk.c index f899488f..a37a60cf 100644 --- a/src/base/cba/cbaNtk.c +++ b/src/base/cba/cbaNtk.c @@ -26,6 +26,177 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// +typedef struct Cba_Pair_t_ Cba_Pair_t; +struct Cba_Pair_t_ +{ + Cba_ObjType_t Type; + char * pName; + char * pSymb; +}; +static const char * s_Pref = "ABC_"; +static Cba_Pair_t s_Types[CBA_BOX_UNKNOWN] = +{ + { CBA_OBJ_NONE, "NONE", NULL }, + { CBA_OBJ_PI, "PI", NULL }, + { CBA_OBJ_PO, "PO", NULL }, + { CBA_OBJ_BI, "BI", NULL }, + { CBA_OBJ_BO, "BO", NULL }, + { CBA_OBJ_BOX, "BOX", NULL }, + + { CBA_BOX_CF, "CF", "o" }, + { CBA_BOX_CT, "CT", "o" }, + { CBA_BOX_CX, "CX", "o" }, + { CBA_BOX_CZ, "CZ", "o" }, + { CBA_BOX_BUF, "BUF", "ao" }, + { CBA_BOX_INV, "INV", "ao" }, + { CBA_BOX_AND, "AND", "abo" }, + { CBA_BOX_NAND, "NAND", "abo" }, + { CBA_BOX_OR, "OR", "abo" }, + { CBA_BOX_NOR, "NOR", "abo" }, + { CBA_BOX_XOR, "XOR", "abo" }, + { CBA_BOX_XNOR, "XNOR", "abo" }, + { CBA_BOX_SHARP, "SHARP", "abo" }, + { CBA_BOX_SHARPL, "SHARPL", "abo" }, + { CBA_BOX_MUX, "MUX", "cabo" }, + { CBA_BOX_MAJ, "MAJ", "abco" }, + + { CBA_BOX_RAND, "RAND", "ao" }, + { CBA_BOX_RNAND, "RNAND", "ao" }, + { CBA_BOX_ROR, "ROR", "ao" }, + { CBA_BOX_RNOR, "RNOR", "ao" }, + { CBA_BOX_RXOR, "RXOR", "ao" }, + { CBA_BOX_RXNOR, "RXNOR", "ao" }, + + { CBA_BOX_LAND, "LAND", "abo" }, + { CBA_BOX_LNAND, "LNAND", "abo" }, + { CBA_BOX_LOR, "LOR", "abo" }, + { CBA_BOX_LNOR, "LNOR", "abo" }, + { CBA_BOX_LXOR, "LXOR", "abo" }, + { CBA_BOX_LXNOR, "LXNOR", "abo" }, + + { CBA_BOX_NMUX, "NMUX", "abo" }, + { CBA_BOX_SEL, "SEL", "abo" }, + { CBA_BOX_PSEL, "PSEL", "iabo" }, + { CBA_BOX_ENC, "ENC", "ao" }, + { CBA_BOX_PENC, "PENC", "ao" }, + { CBA_BOX_DEC, "DEC", "ao" }, + { CBA_BOX_EDEC, "EDEC", "abo" }, + + { CBA_BOX_ADD, "ADD", "iabso" }, + { CBA_BOX_SUB, "SUB", "abo" }, + { CBA_BOX_MUL, "MUL", "abo" }, + { CBA_BOX_DIV, "DIV", "abo" }, + { CBA_BOX_MOD, "MOD", "abo" }, + { CBA_BOX_REM, "REM", "abo" }, + { CBA_BOX_POW, "POW", "abo" }, + { CBA_BOX_MIN, "MIN", "ao" }, + { CBA_BOX_ABS, "ABS", "ao" }, + + { CBA_BOX_LTHAN, "LTHAN", "iabo" }, + { CBA_BOX_LETHAN, "LETHAN", "abo" }, + { CBA_BOX_METHAN, "METHAN", "abo" }, + { CBA_BOX_MTHAN, "MTHAN", "abo" }, + { CBA_BOX_EQU, "EQU", "abo" }, + { CBA_BOX_NEQU, "NEQU", "abo" }, + + { CBA_BOX_SHIL, "SHIL", "abo" }, + { CBA_BOX_SHIR, "SHIR", "abo" }, + { CBA_BOX_ROTL, "ROTL", "abo" }, + { CBA_BOX_ROTR, "ROTR", "abo" }, + + { CBA_BOX_GATE, "GATE", "io" }, + { CBA_BOX_LUT, "LUT", "io" }, + { CBA_BOX_ASSIGN, "ASSIGN", "abo" }, + + { CBA_BOX_TRI, "TRI", "abo" }, + { CBA_BOX_RAM, "RAM", "eadro" }, + { CBA_BOX_RAMR, "RAMR", "eamo" }, + { CBA_BOX_RAMW, "RAMW", "eado" }, + { CBA_BOX_RAMWC, "RAMWC", "ceado" }, + { CBA_BOX_RAMBOX, "RAMBOX", "io" }, + + { CBA_BOX_LATCH, "LATCH", "dvsgq" }, + { CBA_BOX_LATCHRS, "LATCHRS", "dsrgq" }, + { CBA_BOX_DFF, "DFF", "dvscq" }, + { CBA_BOX_DFFRS, "DFFRS", "dsrcq" } +}; +static inline int Cba_GetTypeId( Cba_ObjType_t Type ) +{ + int i; + for ( i = 1; i < CBA_BOX_UNKNOWN; i++ ) + if ( s_Types[i].Type == Type ) + return i; + return -1; +} +void Cba_ManSetupTypes( char ** pNames, char ** pSymbs ) +{ + int Type, Id; + for ( Type = 1; Type < CBA_BOX_UNKNOWN; Type++ ) + { + Id = Cba_GetTypeId( Type ); + pNames[Type] = s_Types[Id].pName; + pSymbs[Type] = s_Types[Id].pSymb; + } +} + +char * Cba_NtkGenerateName( Cba_Ntk_t * p, Cba_ObjType_t Type, Vec_Int_t * vBits ) +{ + static char Buffer[100]; + char * pTemp; int i, Bits; + char * pName = Cba_ManPrimName( p->pDesign, Type ); + char * pSymb = Cba_ManPrimSymb( p->pDesign, Type ); + assert( Vec_IntSize(vBits) == (int)strlen(pSymb) ); + sprintf( Buffer, "%s%s_", s_Pref, pName ); + pTemp = Buffer + strlen(Buffer); + Vec_IntForEachEntry( vBits, Bits, i ) + { + sprintf( pTemp, "%c%d", pSymb[i], Bits ); + pTemp += strlen(pTemp); + } + //Vec_IntPrint( vBits ); + //printf( "%s\n", Buffer ); + return Buffer; +} + +Cba_ObjType_t Cba_NameToType( char * pName ) +{ + int i; + if ( strncmp(pName, s_Pref, strlen(s_Pref)) ) + return 0; + pName += strlen(s_Pref); + for ( i = 1; i < CBA_BOX_UNKNOWN; i++ ) + if ( !strncmp(pName, s_Types[i].pName, strlen(s_Types[i].pName)) ) + return s_Types[i].Type; + return 0; +} +Vec_Int_t * Cba_NameToRanges( char * pName ) +{ + static Vec_Int_t Bits, * vBits = &Bits; + static int pArray[10]; + char * pTemp; + int Num = 0, Count = 0; + // initialize array + vBits->pArray = pArray; + vBits->nSize = 0; + vBits->nCap = 10; + // check the name + assert( !strncmp(pName, s_Pref, strlen(s_Pref)) ); + for ( pTemp = pName; *pTemp && !Cba_CharIsDigit(*pTemp); pTemp++ ); + assert( Cba_CharIsDigit(*pTemp) ); + for ( ; *pTemp; pTemp++ ) + { + if ( Cba_CharIsDigit(*pTemp) ) + Num = 10 * Num + *pTemp - '0'; + else + Vec_IntPush( vBits, Num ), Count += Num, Num = 0; + } + assert( Num > 0 ); + Vec_IntPush( vBits, Num ); Count += Num; + assert( Vec_IntSize(vBits) <= 10 ); + return vBits; +} + + //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -116,80 +287,60 @@ int Cba_ManAssignInternTwo( Cba_Ntk_t * p, int iNum, int nDigits, int fPis, Vec_ Vec_IntWriteEntry( vMap, NameId, iNum ); return NameId; } -void Cba_ManPrepareBitNames( Cba_Ntk_t * p, Vec_Int_t * vMap, int * pnNames, int nDigits, int fPis, Vec_Int_t * vRanges, Vec_Int_t * vNames ) -{ - int i, k, Range; - Vec_IntClear( vNames ); - Vec_IntForEachEntry( vRanges, Range, i ) - { - assert( Range > 0 ); - if ( Range == 1 ) - Vec_IntPush( vNames, Abc_Var2Lit2( Cba_ManAssignInternTwo(p, (*pnNames)++, nDigits, fPis, vMap), CBA_NAME_BIN ) ); - else - { - Vec_IntPush( vNames, Abc_Var2Lit2( Cba_ManAssignInternTwo(p, (*pnNames)++, nDigits, fPis, vMap), CBA_NAME_WORD ) ); - for ( k = 1; k < Range; k++ ) - Vec_IntPush( vNames, Abc_Var2Lit2( k, CBA_NAME_INDEX ) ); - } - } -} int Cba_ManAssignCountNames( Cba_Ntk_t * p ) { - int iBox, Counter = 1; - Vec_Int_t * vRanges = &p->pDesign->pNtks->vArray; - Cba_NtkReadRangesUser( p, vRanges, 0 ); - Counter += Vec_IntSize(vRanges); - Cba_NtkReadRangesUser( p, vRanges, 1 ); - Counter += Vec_IntSize(vRanges); + int i, iObj, iBox, Count = 0; + Cba_NtkForEachPiMain( p, iObj, i ) + if ( !Cba_ObjNameInt(p, iObj) ) + Count++; Cba_NtkForEachBox( p, iBox ) - { - if ( Cba_ObjIsBoxUser(p, iBox) ) - Cba_NtkReadRangesUser( Cba_BoxNtk(p, iBox), vRanges, 1 ); - else if ( Cba_BoxNtkId(p, iBox) ) - Cba_NtkReadRangesPrim( Cba_BoxNtkName(p, iBox), vRanges, 1 ); - else assert( 0 ); - Counter += Vec_IntSize(vRanges); - } - return Counter; + Cba_BoxForEachBoMain( p, iBox, iObj, i ) + if ( !Cba_ObjNameInt(p, iObj) ) + Count++; + return Count; } void Cba_ManAssignInternWordNamesNtk( Cba_Ntk_t * p, Vec_Int_t * vMap ) { - Vec_Int_t * vRanges = &p->pDesign->pNtks->vArray; - Vec_Int_t * vNames = &p->pDesign->pNtks->vArray2; - int k, nPis = 0, nPos = 0, iObj, iTerm, nNames = 1; - int nDigits = Abc_Base10Log( Cba_ManAssignCountNames(p) ); - assert( Cba_NtkReadRangesUser(p, NULL, 0) == Cba_NtkPiNum(p) ); - assert( Cba_NtkReadRangesUser(p, NULL, 1) == Cba_NtkPoNum(p) ); + int k, iObj, iTerm, iName = -1, iBit = -1; + int nDigits, nPis = 0, nPos = 0, nNames = 1; // start names - assert( !Cba_NtkHasNames(p) ); - Cba_NtkStartNames(p); - // derive PI names - Cba_NtkReadRangesUser( p, vRanges, 0 ); - Cba_ManPrepareBitNames( p, vMap, &nNames, nDigits, 1, vRanges, vNames ); - assert( Vec_IntSize(vNames) == Cba_NtkPiNum(p) ); - Cba_NtkForEachPi( p, iObj, k ) - Cba_ObjSetName( p, iObj, Vec_IntEntry(vNames, k) ); - // derive box output names - Cba_NtkForEachBox( p, iObj ) + if ( !Cba_NtkHasNames(p) ) + Cba_NtkStartNames(p); + nDigits = Abc_Base10Log( Cba_ManAssignCountNames(p) ); + // assign CI names + Cba_NtkForEachCi( p, iObj ) { - if ( Cba_ObjIsBoxUser(p, iObj) ) - Cba_NtkReadRangesUser( Cba_BoxNtk(p, iObj), vRanges, 1 ); - else if ( Cba_BoxNtkId(p, iObj) ) - Cba_NtkReadRangesPrim( Cba_BoxNtkName(p, iObj), vRanges, 1 ); - else assert( 0 ); - Cba_ManPrepareBitNames( p, vMap, &nNames, nDigits, 0, vRanges, vNames ); - assert( Vec_IntSize(vNames) == Cba_BoxBoNum(p, iObj) ); - Cba_BoxForEachBo( p, iObj, iTerm, k ) - Cba_ObjSetName( p, iTerm, Vec_IntEntry(vNames, k) ); + if ( Cba_ObjNameInt(p, iObj) ) + { + iName = -1; + iBit = -1; + continue; + } + if ( Cba_ObjBit(p, iObj) ) + { + assert( iBit > 0 ); + Cba_ObjSetName( p, iObj, Abc_Var2Lit2(iBit++, CBA_NAME_INDEX) ); + } + else + { + int Type = Cba_ObjType(p, iObj); + int Range = Cba_ObjIsPi(p, iObj) ? Cba_ObjPiRange(p, iObj) : Cba_BoxBoRange(p, iObj); + iName = Cba_ManAssignInternTwo( p, nNames++, nDigits, Cba_ObjIsPi(p, iObj), vMap ); + if ( Range == 1 ) + Cba_ObjSetName( p, iObj, Abc_Var2Lit2(iName, CBA_NAME_BIN) ); + else + Cba_ObjSetName( p, iObj, Abc_Var2Lit2(iName, CBA_NAME_WORD) ); + iBit = 1; + } } // transfer names to the interface -// Cba_NtkReadRangesUser( p, vRanges, 1 ); for ( k = 0; k < Cba_NtkInfoNum(p); k++ ) { - char * pName = Cba_NtkName(p); + //char * pName = Cba_NtkName(p); if ( Cba_NtkInfoType(p, k) == 1 ) // PI { iObj = Cba_NtkPi(p, nPis); + assert( !Cba_ObjBit(p, iObj) ); assert( Cba_ObjNameType(p, iObj) <= CBA_NAME_WORD ); Cba_NtkSetInfoName( p, k, Abc_Var2Lit2(Cba_ObjNameId(p, iObj), 1) ); nPis += Cba_NtkInfoRange(p, k); @@ -197,6 +348,7 @@ void Cba_ManAssignInternWordNamesNtk( Cba_Ntk_t * p, Vec_Int_t * vMap ) else if ( Cba_NtkInfoType(p, k) == 2 ) // PO { iObj = Cba_NtkPo(p, nPos); + assert( !Cba_ObjBit(p, iObj) ); iObj = Cba_ObjFanin(p, iObj); assert( Cba_ObjNameType(p, iObj) <= CBA_NAME_WORD ); Cba_NtkSetInfoName( p, k, Abc_Var2Lit2(Cba_ObjNameId(p, iObj), 2) ); @@ -214,9 +366,7 @@ void Cba_ManAssignInternWordNamesNtk( Cba_Ntk_t * p, Vec_Int_t * vMap ) Cba_BoxForEachBo( p, iObj, iTerm, k ) if ( Cba_ObjNameType(p, iTerm) <= CBA_NAME_WORD ) Vec_IntWriteEntry( vMap, Cba_ObjNameId(p, iTerm), 0 ); - printf( "Generated %d word-level names.\n", nNames-1 ); -// Vec_IntPrint( &p->vName ); -// Vec_IntPrint( &p->vInfo ); +// printf( "Generated %d word-level names.\n", nNames-1 ); } void Cba_ManAssignInternWordNames( Cba_Man_t * p ) { @@ -230,91 +380,6 @@ void Cba_ManAssignInternWordNames( Cba_Man_t * p ) /**Function************************************************************* - Synopsis [Assigns bit-level names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_ManSetInternOne( Cba_Ntk_t * p, int iTerm, Vec_Int_t * vMap ) -{ - if ( !Cba_ObjName(p, iTerm) ) - return 1; - if ( Cba_ObjNameType(p, iTerm) > CBA_NAME_WORD ) - return 0; - assert( Vec_IntEntry(vMap, Cba_ObjNameId(p, iTerm)) == 0 ); - Vec_IntWriteEntry( vMap, Cba_ObjNameId(p, iTerm), iTerm+1 ); - return 0; -} -int Cba_ManAssignInternOne( Cba_Ntk_t * p, int iTerm, Vec_Int_t * vMap ) -{ - char Buffer[16]; - int i = 0, NameId, nDigits; - if ( Cba_ObjName(p, iTerm) ) - return 0; - do - { - nDigits = Abc_Base10Log( Cba_NtkObjNum(p) ); - if ( i == 0 ) - sprintf( Buffer, "%s%0*d", "n", nDigits, iTerm ); - else - sprintf( Buffer, "%s%0*d_%d", "n", nDigits, iTerm, ++i ); - NameId = Abc_NamStrFindOrAdd( p->pDesign->pStrs, Buffer, NULL ); - } - while ( Vec_IntEntry(vMap, NameId) ); - Cba_ObjSetName( p, iTerm, Abc_Var2Lit2(NameId, CBA_NAME_BIN) ); - Vec_IntWriteEntry( vMap, NameId, iTerm+1 ); - return 1; -} -void Cba_ManAssignInternNamesNtk( Cba_Ntk_t * p, Vec_Int_t * vMap ) -{ - int i, iObj, iTerm, nNameless = 0; -// Vec_IntPrint( &p->vName ); - if ( !Cba_NtkHasNames(p) ) - Cba_NtkStartNames(p); - // set all names - Cba_NtkForEachPi( p, iObj, i ) - nNameless += Cba_ManSetInternOne( p, iObj, vMap ); - Cba_NtkForEachBox( p, iObj ) - Cba_BoxForEachBo( p, iObj, iTerm, i ) - nNameless += Cba_ManSetInternOne( p, iTerm, vMap ); - // generate new names - if ( nNameless ) - { - int nNameless2 = 0; - Cba_NtkForEachPi( p, iObj, i ) - nNameless2 += Cba_ManAssignInternOne( p, iObj, vMap ); - Cba_NtkForEachBox( p, iObj ) - Cba_BoxForEachBo( p, iObj, iTerm, i ) - nNameless2 += Cba_ManAssignInternOne( p, iTerm, vMap ); - assert( nNameless == nNameless2 ); - if ( nNameless ) - printf( "Generated unique names for %d objects in network \"%s\".\n", nNameless, Cba_NtkName(p) ); - } - // unmark all names - Cba_NtkForEachPi( p, iObj, i ) - if ( Cba_ObjNameType(p, iObj) <= CBA_NAME_WORD ) - Vec_IntWriteEntry( vMap, Cba_ObjNameId(p, iObj), 0 ); - Cba_NtkForEachBox( p, iObj ) - Cba_BoxForEachBo( p, iObj, iTerm, i ) - if ( Cba_ObjNameType(p, iTerm) <= CBA_NAME_WORD ) - Vec_IntWriteEntry( vMap, Cba_ObjNameId(p, iTerm), 0 ); -} -void Cba_ManAssignInternNames( Cba_Man_t * p ) -{ - Vec_Int_t * vMap = Vec_IntStart( Cba_ManObjNum(p) ); - Cba_Ntk_t * pNtk; int i; - Cba_ManForEachNtk( p, pNtk, i ) - Cba_ManAssignInternNamesNtk( pNtk, vMap ); - Vec_IntFree( vMap ); -} - - -/**Function************************************************************* - Synopsis [Count number of objects after collapsing.] Description [] diff --git a/src/base/cba/cbaOper.c b/src/base/cba/cbaOper.c index bc160fd3..4fe6d852 100644 --- a/src/base/cba/cbaOper.c +++ b/src/base/cba/cbaOper.c @@ -213,7 +213,7 @@ int Cba_ObjClpArith( Cba_Ntk_t * p, int iBox ) { Cba_ObjType_t Type = Cba_ObjType( p, iBox ); int i, iObj = -1; - int nBis = Cba_NtkReadRangesPrim( Cba_BoxNtkName(p, iObj), &p->vArray, 0 ); + int nBis = 0;//Cba_NtkReadRangesPrim( Cba_BoxNtkName(p, iObj), &p->vArray, 0 ); assert( nBis == Cba_BoxBiNum(p, iBox) ); if ( Type == CBA_BOX_ADD ) { diff --git a/src/base/cba/cbaPrsTrans.c b/src/base/cba/cbaPrsTrans.c index b3cd6625..31f01ba8 100644 --- a/src/base/cba/cbaPrsTrans.c +++ b/src/base/cba/cbaPrsTrans.c @@ -27,6 +27,99 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// +typedef struct Cba_Trip_t_ Cba_Trip_t; +struct Cba_Trip_t_ +{ + Cba_ObjType_t Type; + char * pName; + char * pCode; + char * pSigs[6]; +}; +static Cba_Trip_t s_Types[100] = +{ + { CBA_BOX_CT , "VERIFIC_PWR", "1", {"o"} }, + { CBA_BOX_CF , "VERIFIC_GND", "1", {"o"} }, + { CBA_BOX_CX , "VERIFIC_X", "1", {"o"} }, + { CBA_BOX_CZ , "VERIFIC_Z", "1", {"o"} }, + { CBA_BOX_INV , "VERIFIC_INV", "11", {"i","o"} }, + { CBA_BOX_BUF , "VERIFIC_BUF", "11", {"i","o"} }, + { CBA_BOX_AND , "VERIFIC_AND", "111", {"a0","a1","o"} }, + { CBA_BOX_NAND , "VERIFIC_NAND", "111", {"a0","a1","o"} }, + { CBA_BOX_OR , "VERIFIC_OR", "111", {"a0","a1","o"} }, + { CBA_BOX_NOR , "VERIFIC_NOR", "111", {"a0","a1","o"} }, + { CBA_BOX_XOR , "VERIFIC_XOR", "111", {"a0","a1","o"} }, + { CBA_BOX_XNOR , "VERIFIC_XNOR", "111", {"a0","a1","o"} }, + { CBA_BOX_MUX , "VERIFIC_MUX", "1111", {"c","a1","a0","o"} }, // changed order + { (Cba_ObjType_t)-1, "VERIFIC_PULLUP", "1", {"o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_PULLDOWN", "1", {"o"} }, + { CBA_BOX_TRI , "VERIFIC_TRI", "111", {"i","c","o"} }, + { CBA_BOX_LATCH , "VERIFIC_DLATCH", "11111", {"d","async_val","async_cond","gate","q"} }, // changed order + { CBA_BOX_LATCHRS , "VERIFIC_DLATCHRS", "11111", {"d","s","r","gate","q"} }, // changed order + { CBA_BOX_DFF , "VERIFIC_DFF", "11111", {"d","async_val","async_cond","clk","q"} }, // changed order + { CBA_BOX_DFFRS , "VERIFIC_DFFRS", "11111", {"d","s","r","clk","q"} }, // changed order + { (Cba_ObjType_t)-1, "VERIFIC_NMOS", "111", {"c","d","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_PMOS", "111", {"c","d","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_CMOS", "1111", {"d","nc","pc","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_TRAN", "111", {"inout1","inout2","control"} }, + { CBA_BOX_ADD , "VERIFIC_FADD", "11111", {"cin","a","b","o","cout"} }, + { (Cba_ObjType_t)-1, "VERIFIC_RCMOS", "1111", {"d","nc","pc","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_RNMOS", "111", {"c","d","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_RPMOS", "111", {"c","d","o"} }, + { (Cba_ObjType_t)-1, "VERIFIC_RTRAN", "111", {"inout1","inout2","control"} }, + { (Cba_ObjType_t)-1, "VERIFIC_HDL_ASSERTION", "1", {"condition"} }, + { CBA_BOX_ADD , "add_", "1aba1", {"cin","a","b","o","cout"} }, + { CBA_BOX_MUL , "mult_", "ab?", {"a","b","o"} }, // ? = a * b + { CBA_BOX_DIV , "div_", "ab?", {"a","b","o"} }, // ? = + { CBA_BOX_MOD , "mod_", "ab?", {"a","b","o"} }, // ? = + { CBA_BOX_REM , "rem_", "ab?", {"a","b","o"} }, // ? = + { CBA_BOX_SHIL , "shift_left_", "1aba", {"cin","a","amount","o"} }, + { CBA_BOX_SHIR , "shift_right_", "1aba", {"cin","a","amount","o"} }, + { CBA_BOX_ROTL , "rotate_left_", "aba", {"a","amount","o"} }, + { CBA_BOX_ROTR , "rotate_right_", "aba", {"a","amount","o"} }, + { CBA_BOX_RAND , "reduce_and_", "ab1", {"a","o"} }, + { CBA_BOX_ROR , "reduce_or_", "ab1", {"a","o"} }, + { CBA_BOX_RXOR , "reduce_xor_", "ab1", {"a","o"} }, + { CBA_BOX_RNAND , "reduce_nand_", "ab1", {"a","o"} }, + { CBA_BOX_RNOR , "reduce_nor_", "ab1", {"a","o"} }, + { CBA_BOX_RXNOR , "reduce_xnor_", "ab1", {"a","o"} }, + { CBA_BOX_LTHAN , "LessThan_", "1ab1", {"cin","a","b","o"} }, + { CBA_BOX_NMUX , "Mux_", "ab1", {"sel","data","o"} }, + { CBA_BOX_SEL , "Select_", "aaa", {"sel","data","o"} }, + { CBA_BOX_DEC , "Decoder_", "a?", {"a","o"} }, // ? = (1 << a) + { CBA_BOX_EDEC , "EnabledDecoder_", "1a?", {"en","i","o"} }, // ? = (1 << a) + { CBA_BOX_PSEL , "PrioSelect_", "1aaa", {"cin","sel","data","o"} }, + { CBA_BOX_RAM , "DualPortRam_", "1abab", {"write_enable","write_address","write_data","read_address","read_data"} }, + { CBA_BOX_RAMR , "ReadPort_", "1a1b", {"read_enable", "read_address", "RAM", "read_data" } }, + { CBA_BOX_RAMW , "WritePort_", "1ab1", {"write_enable","write_address","write_data", "RAM"} }, + { CBA_BOX_RAMWC , "ClockedWritePort_", "11ab1", {"clk","write_enable","write_address","write_data", "RAM"} }, + { CBA_BOX_LUT , "lut", "?", {"i","o"} }, + { CBA_BOX_AND , "and_", "aaa", {"a","b","o"} }, + { CBA_BOX_OR , "or_", "aaa", {"a","b","o"} }, + { CBA_BOX_XOR , "xor_", "aaa", {"a","b","o"} }, + { CBA_BOX_NAND , "nand_", "aaa", {"a","b","o"} }, + { CBA_BOX_NOR , "nor_", "aaa", {"a","b","o"} }, + { CBA_BOX_XNOR , "xnor_", "aaa", {"a","b","o"} }, + { CBA_BOX_BUF , "buf_", "aa", {"i","o"} }, + { CBA_BOX_INV , "inv_", "aa", {"i","o"} }, + { CBA_BOX_TRI , "tri_", "a1a", {"i","c","o"} }, + { CBA_BOX_SUB , "sub_", "aaa", {"a","b","o"} }, + { CBA_BOX_MIN , "unary_minus_", "aa", {"i","o"} }, + { CBA_BOX_EQU , "equal_", "aa1", {"a","b","o"} }, + { CBA_BOX_NEQU , "not_equal_", "aa1", {"a","b","o"} }, + { CBA_BOX_MUX , "mux_", "1aaa", {"cond","d1","d0","o"} }, // changed order + { CBA_BOX_NMUX , "wide_mux_", "ab?", {"sel","data","o"} }, // ? = b / (1 << a) + { CBA_BOX_SEL , "wide_select_", "ab?", {"sel","data","o"} }, // ? = b / a + { CBA_BOX_DFF , "wide_dff_", "aaa1a", {"d","async_val","async_cond","clock","q"} }, + { CBA_BOX_DFFRS , "wide_dlatch_", "aaa1a", {"d","set","reset","clock","q"} }, + { CBA_BOX_LATCHRS , "wide_dffrs_", "aaa1a", {"d","set","reset","clock","q"} }, + { CBA_BOX_LATCH , "wide_dlatchrs_", "aaa1a", {"d","async_val","async_cond","clock","q"} }, + { CBA_BOX_PSEL , "wide_prio_select_", "ab??", {"sel","data","carry_in","o"} }, // ? = b / a + { CBA_BOX_POW , "pow_", "abc", {"a","b","o"} }, // ? = + { CBA_BOX_PENC , "PrioEncoder_", "a?", {"sel","o"} }, + { CBA_BOX_ABS , "abs", "aa", {"i","o"} } +}; + + //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaPtrAbc.c b/src/base/cba/cbaPtrAbc.c index 60fdcb02..38391004 100644 --- a/src/base/cba/cbaPtrAbc.c +++ b/src/base/cba/cbaPtrAbc.c @@ -462,7 +462,7 @@ Vec_Ptr_t * Cba_PtrDeriveFromCba( Cba_Man_t * p ) Cba_Ntk_t * pTemp; int i; if ( p == NULL ) return NULL; - Cba_ManAssignInternNames( p ); + Cba_ManAssignInternWordNames( p ); vDes = Vec_PtrAllocExact( 1 + Cba_ManNtkNum(p) ); Vec_PtrPush( vDes, p->pName ); Cba_ManForEachNtk( p, pTemp, i ) diff --git a/src/base/cba/cbaReadVer.c b/src/base/cba/cbaReadVer.c index 84bb1737..2704022e 100644 --- a/src/base/cba/cbaReadVer.c +++ b/src/base/cba/cbaReadVer.c @@ -101,18 +101,12 @@ static inline int Prs_ManIsDigit( Prs_Man_t * p ) { return Prs_CharIsD ***********************************************************************/ // collect predefined modules names -const char * s_KnownModules[100] = { - NULL, // CBA_OBJ_NONE = 0, // 0: unused - NULL, // CBA_OBJ_PI, // 1: input - NULL, // CBA_OBJ_PO, // 2: output - NULL, // CBA_OBJ_BI, // 3: box input - NULL, // CBA_OBJ_BO, // 4: box output - NULL, // CBA_OBJ_BOX, // 5: box - - "const0", // CBA_BOX_C0, - "const1", // CBA_BOX_C1, - "constX", // CBA_BOX_CX, - "constZ", // CBA_BOX_CZ, +const char * s_VerilogModules[100] = +{ + "const0", // CBA_BOX_CF, + "const1", // CBA_BOX_CT, + "constX", // CBA_BOX_CX, + "constZ", // CBA_BOX_CZ, "buf", // CBA_BOX_BUF, "not", // CBA_BOX_INV, "and", // CBA_BOX_AND, @@ -124,7 +118,10 @@ const char * s_KnownModules[100] = { "sharp", // CBA_BOX_SHARP, "mux", // CBA_BOX_MUX, "maj", // CBA_BOX_MAJ, - + NULL +}; +const char * s_KnownModules[100] = +{ "VERIFIC_", "add_", "mult_", @@ -179,11 +176,20 @@ const char * s_KnownModules[100] = { NULL }; +// check if it is a Verilog predefined module +static inline int Prs_ManIsVerilogModule( Prs_Man_t * p, char * pName ) +{ + int i; + for ( i = 0; s_VerilogModules[i]; i++ ) + if ( !strcmp(pName, s_VerilogModules[i]) ) + return CBA_BOX_CF + i; + return 0; +} // check if it is a known module static inline int Prs_ManIsKnownModule( Prs_Man_t * p, char * pName ) { int i; - for ( i = CBA_BOX_CF; s_KnownModules[i]; i++ ) + for ( i = 0; s_KnownModules[i]; i++ ) if ( !strncmp(pName, s_KnownModules[i], strlen(s_KnownModules[i])) ) return i; return 0; @@ -306,11 +312,14 @@ static inline int Prs_ManReadNameList( Prs_Man_t * p, Vec_Int_t * vTemp, char La { int Item = Prs_ManReadName(p); if ( Item == 0 ) return Prs_ManErrorSet(p, "Cannot read name in the list.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 1.", 0); + if ( Item == PRS_VER_WIRE ) + continue; Vec_IntPush( vTemp, Item ); if ( Prs_ManIsChar(p, LastSymb) ) break; if ( !Prs_ManIsChar(p, ',') ) return Prs_ManErrorSet(p, "Expecting comma in the list.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 2.", 0); } return 1; } @@ -368,19 +377,19 @@ static inline int Prs_ManReadRange( Prs_Man_t * p ) assert( Prs_ManIsChar(p, '[') ); Vec_StrClear( &p->vCover ); Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 3.", 0); if ( !Prs_ManIsDigit(p) ) return Prs_ManErrorSet(p, "Cannot read digit in range specification.", 0); while ( Prs_ManIsDigit(p) ) Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 4.", 0); if ( Prs_ManIsChar(p, ':') ) { Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 5.", 0); if ( !Prs_ManIsDigit(p) ) return Prs_ManErrorSet(p, "Cannot read digit in range specification.", 0); while ( Prs_ManIsDigit(p) ) Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 6.", 0); } if ( !Prs_ManIsChar(p, ']') ) return Prs_ManErrorSet(p, "Cannot read closing brace in range specification.", 0); Vec_StrPush( &p->vCover, *p->pCur++ ); @@ -392,7 +401,7 @@ static inline int Prs_ManReadConcat( Prs_Man_t * p, Vec_Int_t * vTemp2 ) extern int Prs_ManReadSignalList( Prs_Man_t * p, Vec_Int_t * vTemp, char LastSymb, int fAddForm ); assert( Prs_ManIsChar(p, '{') ); p->pCur++; - if ( !Prs_ManReadSignalList( p, vTemp2, '}', 0 ) ) return 0; + if ( !Prs_ManReadSignalList( p, vTemp2, '}', 0 ) ) return Prs_ManErrorSet(p, "Error number 7.", 0); // check final assert( Prs_ManIsChar(p, '}') ); p->pCur++; @@ -405,12 +414,12 @@ static inline int Prs_ManReadConcat( Prs_Man_t * p, Vec_Int_t * vTemp2 ) static inline int Prs_ManReadSignal( Prs_Man_t * p ) { int Item; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 8.", 0); if ( Prs_ManIsDigit(p) ) { Item = Prs_ManReadConstant(p); - if ( Item == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Item == 0 ) return Prs_ManErrorSet(p, "Error number 9.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); return Abc_Var2Lit2( Item, CBA_PRS_CONST ); } if ( Prs_ManIsChar(p, '{') ) @@ -419,20 +428,20 @@ static inline int Prs_ManReadSignal( Prs_Man_t * p ) p->fUsingTemp2 = 1; Item = Prs_ManReadConcat(p, &p->vTemp2); p->fUsingTemp2 = 0; - if ( Item == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Item == 0 ) return Prs_ManErrorSet(p, "Error number 11.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 12.", 0); return Item; } else { Item = Prs_ManReadName( p ); - if ( Item == 0 ) return 0; // was return 1; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Item == 0 ) return Prs_ManErrorSet(p, "Error number 13.", 0); // was return 1; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 14.", 0); if ( Prs_ManIsChar(p, '[') ) { int Range = Prs_ManReadRange(p); - if ( Range == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Range == 0 ) return Prs_ManErrorSet(p, "Error number 15.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 16.", 0); return Abc_Var2Lit2( Prs_NtkAddSlice(p->pNtk, Item, Range), CBA_PRS_SLICE ); } return Abc_Var2Lit2( Item, CBA_PRS_NAME ); @@ -466,17 +475,17 @@ static inline int Prs_ManReadSignalList2( Prs_Man_t * p, Vec_Int_t * vTemp ) if ( FormId == 0 ) return Prs_ManErrorSet(p, "Cannot read formal name of the instance.", 0); if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Cannot read \"(\" in the instance.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 17.", 0); ActItem = Prs_ManReadSignal( p ); if ( ActItem == 0 ) return Prs_ManErrorSet(p, "Cannot read actual name of the instance.", 0); if ( !Prs_ManIsChar(p, ')') ) return Prs_ManErrorSet(p, "Cannot read \")\" in the instance.", 0); p->pCur++; Vec_IntPushTwo( vTemp, FormId, ActItem ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 18.", 0); if ( Prs_ManIsChar(p, ')') ) break; if ( !Prs_ManIsChar(p, ',') ) return Prs_ManErrorSet(p, "Expecting comma in the instance.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 19.", 0); } assert( Vec_IntSize(vTemp) > 0 ); assert( Vec_IntSize(vTemp) % 2 == 0 ); @@ -500,9 +509,9 @@ static inline int Prs_ManReadDeclaration( Prs_Man_t * p, int Type ) Vec_Int_t * vNames[4] = { &p->pNtk->vInputs, &p->pNtk->vOutputs, &p->pNtk->vInouts, &p->pNtk->vWires }; Vec_Int_t * vNamesR[4] = { &p->pNtk->vInputsR, &p->pNtk->vOutputsR, &p->pNtk->vInoutsR, &p->pNtk->vWiresR }; assert( Type >= PRS_VER_INPUT && Type <= PRS_VER_WIRE ); - if ( Prs_ManUtilSkipSpaces(p) ) return 0; - if ( Prs_ManIsChar(p, '[') && !(RangeId = Prs_ManReadRange(p)) ) return 0; - if ( !Prs_ManReadNameList( p, &p->vTemp, ';' ) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 20.", 0); + if ( Prs_ManIsChar(p, '[') && !(RangeId = Prs_ManReadRange(p)) ) return Prs_ManErrorSet(p, "Error number 21.", 0); + if ( !Prs_ManReadNameList( p, &p->vTemp, ';' ) ) return Prs_ManErrorSet(p, "Error number 22.", 0); Vec_IntForEachEntry( &p->vTemp, NameId, i ) { Vec_IntPush( vNames[Type - PRS_VER_INPUT], NameId ); @@ -514,13 +523,13 @@ static inline int Prs_ManReadDeclaration( Prs_Man_t * p, int Type ) } static inline int Prs_ManReadAssign( Prs_Man_t * p ) { - int OutItem, InItem, fCompl = 0, Oper = 0; + int OutItem, InItem, fCompl = 0, fCompl2 = 0, Oper = 0; // read output name OutItem = Prs_ManReadSignal( p ); if ( OutItem == 0 ) return Prs_ManErrorSet(p, "Cannot read output in assign-statement.", 0); if ( !Prs_ManIsChar(p, '=') ) return Prs_ManErrorSet(p, "Expecting \"=\" in assign-statement.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23.", 0); if ( Prs_ManIsChar(p, '~') ) { fCompl = 1; @@ -546,11 +555,17 @@ static inline int Prs_ManReadAssign( Prs_Man_t * p ) else if ( Prs_ManIsChar(p, '|') ) Oper = CBA_BOX_OR; else if ( Prs_ManIsChar(p, '^') ) - Oper = fCompl ? CBA_BOX_XNOR : CBA_BOX_XOR; + Oper = CBA_BOX_XOR; else if ( Prs_ManIsChar(p, '?') ) Oper = CBA_BOX_MUX; else return Prs_ManErrorSet(p, "Unrecognized operator in the assign-statement.", 0); p->pCur++; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); + if ( Prs_ManIsChar(p, '~') ) + { + fCompl2 = 1; + p->pCur++; + } // read second name InItem = Prs_ManReadSignal( p ); if ( InItem == 0 ) return Prs_ManErrorSet(p, "Cannot read second input name in the assign-statement.", 0); @@ -569,6 +584,31 @@ static inline int Prs_ManReadAssign( Prs_Man_t * p ) Vec_IntPush( &p->vTemp, InItem ); if ( !Prs_ManIsChar(p, ';') ) return Prs_ManErrorSet(p, "Expected semicolon at the end of the assign-statement.", 0); } + else + { + // figure out operator + if ( Oper == CBA_BOX_AND ) + { + if ( fCompl && !fCompl2 ) + Oper = CBA_BOX_SHARPL; + else if ( !fCompl && fCompl2 ) + Oper = CBA_BOX_SHARP; + else if ( fCompl && fCompl2 ) + Oper = CBA_BOX_NOR; + } + else if ( Oper == CBA_BOX_OR ) + { + if ( fCompl && fCompl2 ) + Oper = CBA_BOX_NAND; + else assert( !fCompl && !fCompl2 ); + } + else if ( Oper == CBA_BOX_XOR ) + { + if ( fCompl && !fCompl2 ) + Oper = CBA_BOX_XNOR; + else assert( !fCompl && !fCompl2 ); + } + } // write binary operator Vec_IntPush( &p->vTemp, 0 ); Vec_IntPush( &p->vTemp, OutItem ); @@ -585,27 +625,27 @@ static inline int Prs_ManReadInstance( Prs_Man_t * p, int Func ) int s=0; } */ - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 25.", 0); if ( (InstId = Prs_ManReadName(p)) ) - if (Prs_ManUtilSkipSpaces(p)) return 0; + if (Prs_ManUtilSkipSpaces(p)) return Prs_ManErrorSet(p, "Error number 26.", 0); if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Expecting \"(\" in module instantiation.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 27.", 0); if ( Prs_ManIsChar(p, '.') ) // box Status = Prs_ManReadSignalList2(p, &p->vTemp); else // node { //char * s = Abc_NamStr(p->pStrs, Func); // translate elementary gate - int iFuncNew = Prs_ManIsKnownModule(p, Abc_NamStr(p->pStrs, Func)); + int iFuncNew = Prs_ManIsVerilogModule(p, Abc_NamStr(p->pStrs, Func)); if ( iFuncNew == 0 ) return Prs_ManErrorSet(p, "Cannot find elementary gate.", 0); Func = iFuncNew; Status = Prs_ManReadSignalList( p, &p->vTemp, ')', 1 ); } - if ( Status == 0 ) return 0; + if ( Status == 0 ) return Prs_ManErrorSet(p, "Error number 28.", 0); assert( Prs_ManIsChar(p, ')') ); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 29.", 0); if ( !Prs_ManIsChar(p, ';') ) return Prs_ManErrorSet(p, "Expecting semicolon in the instance.", 0); // add box Prs_NtkAddBox( p->pNtk, Func, InstId, &p->vTemp ); @@ -618,23 +658,23 @@ static inline int Prs_ManReadArguments( Prs_Man_t * p ) Vec_Int_t * vSigsR[3] = { &p->pNtk->vInputsR, &p->pNtk->vOutputsR, &p->pNtk->vInoutsR }; assert( Prs_ManIsChar(p, '(') ); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 30.", 0); while ( 1 ) { int iName = Prs_ManReadName( p ); - if ( iName == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( iName == 0 ) return Prs_ManErrorSet(p, "Error number 31.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 32.", 0); if ( iName >= PRS_VER_INPUT && iName <= PRS_VER_INOUT ) // declaration { iType = iName; if ( Prs_ManIsChar(p, '[') ) { iRange = Prs_ManReadRange(p); - if ( iRange == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( iRange == 0 ) return Prs_ManErrorSet(p, "Error number 33.", 0); + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 34.", 0); } iName = Prs_ManReadName( p ); - if ( iName == 0 ) return 0; + if ( iName == 0 ) return Prs_ManErrorSet(p, "Error number 35.", 0); } if ( iType > 0 ) { @@ -646,7 +686,7 @@ static inline int Prs_ManReadArguments( Prs_Man_t * p ) break; if ( !Prs_ManIsChar(p, ',') ) return Prs_ManErrorSet(p, "Expecting comma in the instance.", 0); p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 0; + if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 36.", 0); } // check final assert( Prs_ManIsChar(p, ')') ); diff --git a/src/base/cba/cbaWriteBlif.c b/src/base/cba/cbaWriteBlif.c index c61b8634..16929001 100644 --- a/src/base/cba/cbaWriteBlif.c +++ b/src/base/cba/cbaWriteBlif.c @@ -132,7 +132,12 @@ void Cba_ManWriteBlifGate( FILE * pFile, Cba_Ntk_t * p, Mio_Gate_t * pGate, Vec_ { int iFanin, i; Vec_IntForEachEntry( vFanins, iFanin, i ) + { + if ( Cba_ObjIsCo(p, iFanin) ) + iFanin = Cba_ObjFanin(p, iFanin); + assert( Cba_ObjIsCi(p, iFanin) ); 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" ); } @@ -140,7 +145,12 @@ void Cba_ManWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, in { int iFanin, i; Vec_IntForEachEntry( vFanins, iFanin, i ) + { + if ( Cba_ObjIsCo(p, iFanin) ) + iFanin = Cba_ObjFanin(p, iFanin); + assert( Cba_ObjIsCi(p, iFanin) ); fprintf( pFile, " %s", Cba_ObjNameStr(p, iFanin) ); + } if ( iObj >= 0 ) fprintf( pFile, " %s", Cba_ObjNameStr(p, iObj) ); fprintf( pFile, "\n" ); @@ -182,7 +192,7 @@ void Cba_ManWriteBlifLines( FILE * pFile, Cba_Ntk_t * p ) { fprintf( pFile, ".names" ); Cba_BoxForEachBi( p, i, iTerm, k ) - fprintf( pFile, " %s", Cba_ObjNameStr(p, iTerm) ); + 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)) ); @@ -220,7 +230,7 @@ void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p ) return; } fprintf( pFile, "# Design \"%s\" written by ABC on %s\n\n", Cba_ManName(p), Extra_TimeStamp() ); - Cba_ManAssignInternNames( p ); + Cba_ManAssignInternWordNames( p ); Cba_ManForEachNtk( p, pNtk, i ) Cba_ManWriteBlifNtk( pFile, pNtk ); fclose( pFile ); diff --git a/src/base/cba/cbaWriteVer.c b/src/base/cba/cbaWriteVer.c index 5bf42759..c8d7839e 100644 --- a/src/base/cba/cbaWriteVer.c +++ b/src/base/cba/cbaWriteVer.c @@ -191,11 +191,25 @@ void Prs_ManWriteVerilog( char * pFileName, Vec_Ptr_t * vPrs ) SeeAlso [] ***********************************************************************/ -void Cba_ManWriteVar( Cba_Ntk_t * p, int RealName ) +// compute range of a name (different from range of a multi-bit wire) +static inline int Cba_ObjGetRange( Cba_Ntk_t * p, int iObj ) +{ + int i, NameId = Cba_ObjName(p, iObj); + assert( Cba_ObjIsCi(p, iObj) ); +// if ( Cba_NameType(NameId) == CBA_NAME_INDEX ) +// NameId = Cba_ObjName(p, iObj - Abc_Lit2Var2(NameId)); + assert( Cba_NameType(NameId) == CBA_NAME_WORD || Cba_NameType(NameId) == CBA_NAME_INFO ); + for ( i = iObj + 1; i < Cba_NtkObjNum(p); i++ ) + if ( !Cba_ObjIsCi(p, i) || Cba_ObjNameType(p, i) != CBA_NAME_INDEX ) + break; + return i - iObj; +} + +static inline void Cba_ManWriteVar( Cba_Ntk_t * p, int RealName ) { Vec_StrPrintStr( p->pDesign->vOut, Cba_NtkStr(p, RealName) ); } -void Cba_ManWriteRange( Cba_Ntk_t * p, int Beg, int End ) +static inline void Cba_ManWriteRange( Cba_Ntk_t * p, int Beg, int End ) { Vec_Str_t * vStr = p->pDesign->vOut; Vec_StrPrintStr( vStr, "[" ); @@ -207,7 +221,7 @@ void Cba_ManWriteRange( Cba_Ntk_t * p, int Beg, int End ) Vec_StrPrintNum( vStr, Beg ); Vec_StrPrintStr( vStr, "]" ); } -void Cba_ManWriteConstBit( Cba_Ntk_t * p, int iObj, int fHead ) +static inline void Cba_ManWriteConstBit( Cba_Ntk_t * p, int iObj, int fHead ) { Vec_Str_t * vStr = p->pDesign->vOut; int Const = Cba_ObjGetConst(p, iObj); @@ -224,7 +238,7 @@ void Cba_ManWriteConstBit( Cba_Ntk_t * p, int iObj, int fHead ) Vec_StrPush( vStr, 'z' ); else assert( 0 ); } -int Cba_ManFindRealNameId( Cba_Ntk_t * p, int iObj ) +static inline int Cba_ManFindRealNameId( Cba_Ntk_t * p, int iObj ) { int NameId = Cba_ObjName(p, iObj); assert( Cba_ObjIsCi(p, iObj) ); @@ -235,7 +249,7 @@ int Cba_ManFindRealNameId( Cba_Ntk_t * p, int iObj ) assert( Cba_NameType(NameId) == CBA_NAME_BIN || Cba_NameType(NameId) == CBA_NAME_WORD ); return Abc_Lit2Var2(NameId); } -int Cba_ManFindRealIndex( Cba_Ntk_t * p, int iObj ) +static inline int Cba_ManFindRealIndex( Cba_Ntk_t * p, int iObj ) { int iBit = 0, NameId = Cba_ObjName(p, iObj); assert( Cba_ObjIsCi(p, iObj) ); @@ -247,7 +261,7 @@ int Cba_ManFindRealIndex( Cba_Ntk_t * p, int iObj ) assert( Cba_NameType(NameId) == CBA_NAME_WORD ); return iBit; } -void Cba_ManWriteSig( Cba_Ntk_t * p, int iObj ) +static inline void Cba_ManWriteSig( Cba_Ntk_t * p, int iObj ) { if ( Cba_ObjIsCo(p, iObj) ) iObj = Cba_ObjFanin(p, iObj); @@ -266,10 +280,7 @@ void Cba_ManWriteSig( Cba_Ntk_t * p, int iObj ) } } } -void Cba_ManWriteConstant( Cba_Ntk_t * p, int iObj ) -{ -} -void Cba_ManWriteConcat( Cba_Ntk_t * p, int iStart, int nObjs ) +static inline void Cba_ManWriteConcat( Cba_Ntk_t * p, int iStart, int nObjs ) { Vec_Str_t * vStr = p->pDesign->vOut; assert( nObjs >= 1 ); @@ -380,7 +391,7 @@ void Cba_ManWriteConcat( Cba_Ntk_t * p, int iStart, int nObjs ) else assert( 0 ); Vec_StrPrintStr( vStr, "}" ); } -void Cba_ManWriteGate( Cba_Ntk_t * p, int iObj ) +static inline void Cba_ManWriteGate( Cba_Ntk_t * p, int iObj ) { Vec_Str_t * vStr = p->pDesign->vOut; int iTerm, k; char * pGateName = Abc_NamStr(p->pDesign->pMods, Cba_BoxNtkId(p, iObj)); @@ -407,7 +418,7 @@ void Cba_ManWriteGate( Cba_Ntk_t * p, int iObj ) } Vec_StrPrintStr( vStr, ");\n" ); } -void Cba_ManWriteAssign( Cba_Ntk_t * p, int iObj ) +static inline void Cba_ManWriteAssign( Cba_Ntk_t * p, int iObj ) { Vec_Str_t * vStr = p->pDesign->vOut; Cba_ObjType_t Type = Cba_ObjType(p, iObj); @@ -438,31 +449,30 @@ void Cba_ManWriteAssign( Cba_Ntk_t * p, int iObj ) } else if ( nInputs == 2 ) { - if ( Type == CBA_BOX_XNOR ) - { + if ( Type == CBA_BOX_NAND || Type == CBA_BOX_NOR || Type == CBA_BOX_XNOR || Type == CBA_BOX_SHARPL ) Vec_StrPrintStr( vStr, "~" ); - Type = CBA_BOX_XOR; - } Cba_ManWriteSig( p, iObj - 1 ); - if ( Type == CBA_BOX_AND ) + if ( Type == CBA_BOX_AND || Type == CBA_BOX_SHARPL ) Vec_StrPrintStr( vStr, " & " ); + else if ( Type == CBA_BOX_SHARP || Type == CBA_BOX_NOR ) + Vec_StrPrintStr( vStr, " & ~" ); else if ( Type == CBA_BOX_OR ) Vec_StrPrintStr( vStr, " | " ); - else if ( Type == CBA_BOX_XOR ) + else if ( Type == CBA_BOX_NAND ) + Vec_StrPrintStr( vStr, " | ~" ); + else if ( Type == CBA_BOX_XOR || Type == CBA_BOX_XNOR ) Vec_StrPrintStr( vStr, " ^ " ); else assert( 0 ); Cba_ManWriteSig( p, iObj - 2 ); } Vec_StrPrintStr( vStr, ";\n" ); } -void Cba_ManWriteVerilogBoxes( Cba_Ntk_t * p ) +void Cba_ManWriteVerilogBoxes( Cba_Ntk_t * p, int fUseAssign ) { Vec_Str_t * vStr = p->pDesign->vOut; int iObj, k, i, o, StartPos; Cba_NtkForEachBox( p, iObj ) // .subckt/.gate/box (formal/actual binding) { - Cba_Ntk_t * pModel = NULL; - char * pName = NULL; // skip constants if ( Cba_ObjIsConst(p, iObj) ) continue; @@ -473,28 +483,24 @@ void Cba_ManWriteVerilogBoxes( Cba_Ntk_t * p ) continue; } // write primitives as assign-statements - if ( Cba_BoxNtkName(p, iObj) == NULL ) + if ( !Cba_ObjIsBoxUser(p, iObj) && fUseAssign ) { Cba_ManWriteAssign( p, iObj ); continue; } // write header - if ( Cba_ObjIsBoxUser(p, iObj) ) - pModel = Cba_BoxNtk( p, iObj ); - else if ( Cba_BoxNtkId(p, iObj) ) - pName = Cba_BoxNtkName(p, iObj); - else assert( 0 ); StartPos = Vec_StrSize(vStr); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, pModel ? Cba_NtkName(pModel) : pName ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Cba_ObjName(p, iObj) ? Cba_ObjNameStr(p, iObj) : "" ); - // write arguments - i = o = 0; - Vec_StrPrintStr( vStr, " (" ); - if ( pModel ) + if ( Cba_ObjIsBoxUser(p, iObj) ) { int Value, Beg, End, Range; + Cba_Ntk_t * pModel = Cba_BoxNtk( p, iObj ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, Cba_NtkName(pModel) ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, Cba_ObjName(p, iObj) ? Cba_ObjNameStr(p, iObj) : "" ); + Vec_StrPrintStr( vStr, " (" ); + // write arguments + i = o = 0; assert( Cba_NtkInfoNum(pModel) ); Vec_IntForEachEntryTriple( &pModel->vInfo, Value, Beg, End, k ) { @@ -518,35 +524,59 @@ void Cba_ManWriteVerilogBoxes( Cba_Ntk_t * p ) else assert( 0 ); Vec_StrPrintStr( vStr, ")" ); } + assert( i == Cba_BoxBiNum(p, iObj) ); + assert( o == Cba_BoxBoNum(p, iObj) ); } - else + else { - int pRanges[8]; char pSymbs[8]; - int nSigs = Cba_NtkNameRanges( pName, pRanges, pSymbs ); - for ( k = 0; k < nSigs; k++ ) + int iTerm, k, Range, iSig = 0; + Vec_Int_t * vBits = Cba_BoxCollectRanges( p, iObj ); + char * pName = Cba_NtkGenerateName( p, Cba_ObjType(p, iObj), vBits ); + char * pSymbs = Cba_ManPrimSymb( p->pDesign, Cba_ObjType(p, iObj) ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, pName ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, Cba_ObjName(p, iObj) ? Cba_ObjNameStr(p, iObj) : "" ); + Vec_StrPrintStr( vStr, " (" ); + // write inputs + Cba_BoxForEachBiMain( p, iObj, iTerm, k ) { - Vec_StrPrintStr( vStr, k ? ", " : "" ); + Range = Vec_IntEntry( vBits, iSig ); + Vec_StrPrintStr( vStr, iSig ? ", " : "" ); + if ( Vec_StrSize(vStr) > StartPos + 70 ) + { + StartPos = Vec_StrSize(vStr); + Vec_StrPrintStr( vStr, "\n " ); + } + Vec_StrPrintStr( vStr, "." ); + Vec_StrPush( vStr, pSymbs[iSig] ); + Vec_StrPrintStr( vStr, "(" ); + Cba_ManWriteConcat( p, iTerm, Range ); + Vec_StrPrintStr( vStr, ")" ); + iSig++; + } + Cba_BoxForEachBoMain( p, iObj, iTerm, k ) + { + Range = Vec_IntEntry( vBits, iSig ); + Vec_StrPrintStr( vStr, iSig ? ", " : "" ); if ( Vec_StrSize(vStr) > StartPos + 70 ) { StartPos = Vec_StrSize(vStr); Vec_StrPrintStr( vStr, "\n " ); } Vec_StrPrintStr( vStr, "." ); - Vec_StrPush( vStr, pSymbs[k] ); + Vec_StrPush( vStr, pSymbs[iSig] ); Vec_StrPrintStr( vStr, "(" ); - if ( k < nSigs - 1 ) - Cba_ManWriteConcat( p, Cba_BoxBi(p, iObj, i), pRanges[k] ), i += pRanges[k]; - else - Cba_ManWriteConcat( p, Cba_BoxBo(p, iObj, o), pRanges[k] ), o += pRanges[k]; + Cba_ManWriteConcat( p, iTerm, Range ); Vec_StrPrintStr( vStr, ")" ); + iSig++; } + assert( iSig == Vec_IntSize(vBits) ); } Vec_StrPrintStr( vStr, ");\n" ); - assert( i == Cba_BoxBiNum(p, iObj) ); - assert( o == Cba_BoxBoNum(p, iObj) ); } } -void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p ) +void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fUseAssign ) { char * pKeyword[4] = { "wire ", "input ", "output ", "inout " }; Vec_Str_t * vStr = p->pDesign->vOut; @@ -622,10 +652,10 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p ) } Vec_StrPrintStr( vStr, "\n" ); // write objects - Cba_ManWriteVerilogBoxes( p ); + Cba_ManWriteVerilogBoxes( p, fUseAssign ); Vec_StrPrintStr( vStr, "endmodule\n\n" ); } -void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p ) +void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p, int fUseAssign ) { Cba_Ntk_t * pNtk; int i; // check the library @@ -637,9 +667,9 @@ void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p ) // derive the stream p->vOut = Vec_StrAlloc( 10000 ); p->vOut2 = Vec_StrAlloc( 1000 ); - Cba_ManAssignInternNames( p ); + Cba_ManAssignInternWordNames( p ); Cba_ManForEachNtk( p, pNtk, i ) - Cba_ManWriteVerilogNtk( pNtk ); + Cba_ManWriteVerilogNtk( pNtk, fUseAssign ); // dump into file if ( p->vOut && Vec_StrSize(p->vOut) > 0 ) { |