diff --git a/Makefile b/Makefile index 8a8058500..7d9e109ac 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ OS := $(shell uname -s) MODULES := \ $(wildcard src/ext*) \ src/base/abc src/base/abci src/base/cmd src/base/io src/base/main src/base/exor \ - src/base/ver src/base/wlc src/base/wln src/base/acb src/base/bac src/base/cba src/base/pla src/base/test \ + src/base/ver src/base/wlc src/base/wln src/base/acb src/base/pla src/base/test \ src/map/mapper src/map/mio src/map/super src/map/if src/map/if/acd \ src/map/amap src/map/cov src/map/scl src/map/mpm src/map/emap \ src/misc/extra src/misc/mvc src/misc/st src/misc/util src/misc/nm \ diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 86a9fd2ca..cab9967d3 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -64,7 +64,6 @@ #include "map/mio/mio.h" #include "opt/fret/fretime.h" #include "opt/nwk/nwkMerge.h" -#include "base/acb/acbPar.h" #include "base/wln/wln.h" #include "misc/extra/extra.h" #include "opt/eslim/eSLIM.h" @@ -132,7 +131,6 @@ static int Abc_CommandLutmin ( Abc_Frame_t * pAbc, int argc, cha static int Abc_CommandMfs ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandMfs2 ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandMfs3 ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Abc_CommandMfse ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandLogicPush ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandTrace ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandGlitch ( Abc_Frame_t * pAbc, int argc, char ** argv ); @@ -991,7 +989,6 @@ void Abc_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "Synthesis", "mfs", Abc_CommandMfs, 1 ); Cmd_CommandAdd( pAbc, "Synthesis", "mfs2", Abc_CommandMfs2, 1 ); Cmd_CommandAdd( pAbc, "Synthesis", "mfs3", Abc_CommandMfs3, 1 ); - Cmd_CommandAdd( pAbc, "Synthesis", "mfse", Abc_CommandMfse, 1 ); Cmd_CommandAdd( pAbc, "Synthesis", "logicpush", Abc_CommandLogicPush, 1 ); Cmd_CommandAdd( pAbc, "Synthesis", "trace", Abc_CommandTrace, 0 ); Cmd_CommandAdd( pAbc, "Synthesis", "glitch", Abc_CommandGlitch, 0 ); @@ -6285,155 +6282,6 @@ usage: return 1; } -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - extern Abc_Ntk_t * Abc_NtkOptMfse( Abc_Ntk_t * pNtk, Acb_Par_t * pPars ); - Abc_Ntk_t * pNtkNew, * pNtk = Abc_FrameReadNtk(pAbc); - Acb_Par_t Pars, * pPars = &Pars; int c; - Acb_ParSetDefault( pPars ); - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "IOWFLCadvwh" ) ) != EOF ) - { - switch ( c ) - { - case 'I': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nTfiLevMax = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nTfiLevMax < 0 ) - goto usage; - break; - case 'O': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nTfoLevMax = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nTfoLevMax < 0 ) - goto usage; - break; - case 'W': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nWinNodeMax = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nWinNodeMax < 0 ) - goto usage; - break; - case 'F': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nFanoutMax = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nFanoutMax < 0 ) - goto usage; - break; - case 'L': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nGrowthLevel = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nGrowthLevel < -ABC_INFINITY || pPars->nGrowthLevel > ABC_INFINITY ) - goto usage; - break; - case 'C': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" ); - goto usage; - } - pPars->nBTLimit = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( pPars->nBTLimit < 0 ) - goto usage; - break; - case 'a': - pPars->fArea ^= 1; - break; - case 'd': - pPars->fUseAshen ^= 1; - break; - case 'v': - pPars->fVerbose ^= 1; - break; - case 'w': - pPars->fVeryVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( pNtk == NULL ) - { - Abc_Print( -1, "Empty network.\n" ); - return 1; - } - if ( !Abc_NtkIsLogic(pNtk) ) - { - Abc_Print( -1, "This command can only be applied to a logic network.\n" ); - return 1; - } - pPars->nLutSize = Abc_NtkGetFaninMax( pNtk ); - if ( pPars->nLutSize > 6 ) - { - Abc_Print( -1, "Command is only applicable to LUT size no more than 6.\n" ); - return 1; - } - Abc_NtkToSop( pNtk, -1, ABC_INFINITY ); - pNtkNew = Abc_NtkOptMfse( pNtk, pPars ); - if ( pNtkNew == NULL ) - { - Abc_Print( -1, "Command \"mfse\" has failed.\n" ); - return 1; - } - Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew ); - return 0; - -usage: - Abc_Print( -2, "usage: mfse [-IOWFLC ] [-advwh]\n" ); - Abc_Print( -2, "\t performs don't-care-based optimization of logic networks\n" ); - Abc_Print( -2, "\t-I : the number of levels in the TFI cone (2 <= num) [default = %d]\n", pPars->nTfiLevMax ); - Abc_Print( -2, "\t-O : the number of levels in the TFO cone (0 <= num) [default = %d]\n", pPars->nTfoLevMax ); - Abc_Print( -2, "\t-W : the max number of nodes in the window (1 <= num) [default = %d]\n", pPars->nWinNodeMax ); - Abc_Print( -2, "\t-F : the max number of fanouts to skip (1 <= num) [default = %d]\n", pPars->nFanoutMax ); - Abc_Print( -2, "\t-L : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel ); - Abc_Print( -2, "\t-C : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n", pPars->nBTLimit ); - Abc_Print( -2, "\t-a : toggle minimizing area [default = %s]\n", pPars->fArea? "area": "delay" ); - Abc_Print( -2, "\t-d : toggle using Ashenhurst decomposition [default = %s]\n", pPars->fUseAshen? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing optimization summary [default = %s]\n", pPars->fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-w : toggle printing detailed stats for each node [default = %s]\n", pPars->fVeryVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - /**Function************************************************************* Synopsis [] diff --git a/src/base/bac/bac.c b/src/base/bac/bac.c deleted file mode 100644 index fdbee7b74..000000000 --- a/src/base/bac/bac.c +++ /dev/null @@ -1,52 +0,0 @@ -/**CFile**************************************************************** - - FileName [bac.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Verilog parser.] - - Synopsis [Parses several flavors of word-level Verilog.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bac.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bac.h b/src/base/bac/bac.h deleted file mode 100644 index bbc8a5fba..000000000 --- a/src/base/bac/bac.h +++ /dev/null @@ -1,1017 +0,0 @@ -/**CFile**************************************************************** - - FileName [bac.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bac.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef ABC__base__bac__bac_h -#define ABC__base__bac__bac_h - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include "aig/gia/gia.h" -#include "misc/extra/extra.h" -#include "misc/util/utilNam.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -// network objects -typedef enum { - BAC_OBJ_NONE = 0, // 0: unused - BAC_OBJ_PI, // 1: input - BAC_OBJ_PO, // 2: output - BAC_OBJ_BI, // 3: box input - BAC_OBJ_BO, // 4: box output - BAC_OBJ_BOX, // 5: box - - BAC_BOX_CF, - BAC_BOX_CT, - BAC_BOX_CX, - BAC_BOX_CZ, - BAC_BOX_BUF, - BAC_BOX_INV, - BAC_BOX_AND, - BAC_BOX_NAND, - BAC_BOX_OR, - BAC_BOX_NOR, - BAC_BOX_XOR, - BAC_BOX_XNOR, - BAC_BOX_SHARP, - BAC_BOX_SHARPL, - BAC_BOX_MUX, - BAC_BOX_MAJ, - - BAC_BOX_RAND, - BAC_BOX_RNAND, - BAC_BOX_ROR, - BAC_BOX_RNOR, - BAC_BOX_RXOR, - BAC_BOX_RXNOR, - - BAC_BOX_LAND, - BAC_BOX_LNAND, - BAC_BOX_LOR, - BAC_BOX_LNOR, - BAC_BOX_LXOR, - BAC_BOX_LXNOR, - - BAC_BOX_NMUX, - BAC_BOX_SEL, - BAC_BOX_PSEL, - BAC_BOX_ENC, - BAC_BOX_PENC, - BAC_BOX_DEC, - BAC_BOX_EDEC, - - BAC_BOX_ADD, - BAC_BOX_SUB, - BAC_BOX_MUL, - BAC_BOX_DIV, - BAC_BOX_MOD, - BAC_BOX_REM, - BAC_BOX_POW, - BAC_BOX_MIN, - BAC_BOX_ABS, - - BAC_BOX_LTHAN, - BAC_BOX_LETHAN, - BAC_BOX_METHAN, - BAC_BOX_MTHAN, - BAC_BOX_EQU, - BAC_BOX_NEQU, - - BAC_BOX_SHIL, - BAC_BOX_SHIR, - BAC_BOX_ROTL, - BAC_BOX_ROTR, - - BAC_BOX_GATE, - BAC_BOX_LUT, - BAC_BOX_ASSIGN, - - BAC_BOX_TRI, - BAC_BOX_RAM, - BAC_BOX_RAMR, - BAC_BOX_RAMW, - BAC_BOX_RAMWC, - BAC_BOX_RAMBOX, - - BAC_BOX_LATCH, - BAC_BOX_LATCHRS, - BAC_BOX_DFF, - BAC_BOX_DFFRS, - - BAC_BOX_UNKNOWN // 67 -} Bac_ObjType_t; - - -// name types -typedef enum { - BAC_NAME_BIN = 0, // 0: binary variable - BAC_NAME_WORD, // 1: first bit of word-level variable - BAC_NAME_INFO, // 2: first bit of special variable - BAC_NAME_INDEX, // 3: index of word-level variable -} Bac_NameType_t; - - -typedef struct Bac_Ntk_t_ Bac_Ntk_t; -typedef struct Bac_Man_t_ Bac_Man_t; - -// network -struct Bac_Ntk_t_ -{ - Bac_Man_t * pDesign; // design - int NameId; // name ID - int iCopy; // copy module - int iBoxNtk; // instance network ID - int iBoxObj; // instance object ID - int Count; // object counter - int Mark; // visit mark - // interface - Vec_Int_t vInputs; // inputs - Vec_Int_t vOutputs; // outputs - Vec_Int_t vInfo; // input/output/wire info - // object attributes - Vec_Str_t vType; // types - Vec_Int_t vFanin; // fanin - Vec_Int_t vIndex; // index - Vec_Int_t vName; // original NameId or InstId - Vec_Int_t vFanout; // fanout - Vec_Int_t vCopy; // copy - // other - Vec_Int_t vArray; - Vec_Int_t vArray2; -}; - -// design -struct Bac_Man_t_ -{ - // design names - char * pName; // design name - char * pSpec; // spec file name - Abc_Nam_t * pStrs; // string manager - Abc_Nam_t * pMods; // module name manager - // internal data - int iRoot; // root network - int nNtks; // number of current networks - Bac_Ntk_t * pNtks; // networks - // user data - Vec_Str_t * vOut; - Vec_Str_t * vOut2; - Vec_Int_t vBuf2RootNtk; - Vec_Int_t vBuf2RootObj; - Vec_Int_t vBuf2LeafNtk; - Vec_Int_t vBuf2LeafObj; - void * pMioLib; - void ** ppGraphs; - int ElemGates[4]; - char * pPrimNames[BAC_BOX_UNKNOWN]; - char * pPrimSymbs[BAC_BOX_UNKNOWN]; -}; - -static inline char * Bac_ManName( Bac_Man_t * p ) { return p->pName; } -static inline char * Bac_ManSpec( Bac_Man_t * p ) { return p->pSpec; } -static inline int Bac_ManNtkNum( Bac_Man_t * p ) { return p->nNtks; } -static inline int Bac_ManPrimNum( Bac_Man_t * p ) { return Abc_NamObjNumMax(p->pMods) - Bac_ManNtkNum(p); } -static inline int Bac_ManNtkIsOk( Bac_Man_t * p, int i ) { return i > 0 && i <= Bac_ManNtkNum(p); } -static inline Bac_Ntk_t * Bac_ManNtk( Bac_Man_t * p, int i ) { return Bac_ManNtkIsOk(p, i) ? p->pNtks + i : NULL; } -static inline int Bac_ManNtkFindId( Bac_Man_t * p, char * pName ) { return Abc_NamStrFind(p->pMods, pName); } -static inline Bac_Ntk_t * Bac_ManNtkFind( Bac_Man_t * p, char * pName ) { return Bac_ManNtk( p, Bac_ManNtkFindId(p, pName) ); } -static inline Bac_Ntk_t * Bac_ManRoot( Bac_Man_t * p ) { return Bac_ManNtk(p, p->iRoot); } -static inline char * Bac_ManStr( Bac_Man_t * p, int i ) { return Abc_NamStr(p->pStrs, i); } -static inline int Bac_ManStrId( Bac_Man_t * p, char * pStr ) { return Abc_NamStrFind(p->pStrs, pStr); } -static inline char * Bac_ManPrimName( Bac_Man_t * p, Bac_ObjType_t Type ) { return p->pPrimNames[Type]; } -static inline char * Bac_ManPrimSymb( Bac_Man_t * p, Bac_ObjType_t Type ) { return p->pPrimSymbs[Type]; } - -static inline int Bac_NtkId( Bac_Ntk_t * p ) { int i = p - p->pDesign->pNtks; assert(Bac_ManNtkIsOk(p->pDesign, i)); return i; } -static inline Bac_Man_t * Bac_NtkMan( Bac_Ntk_t * p ) { return p->pDesign; } -static inline int Bac_NtkNameId( Bac_Ntk_t * p ) { return p->NameId; } -static inline char * Bac_NtkName( Bac_Ntk_t * p ) { return Bac_ManStr(p->pDesign, Bac_NtkNameId(p)); } -static inline int Bac_NtkCopy( Bac_Ntk_t * p ) { return p->iCopy; } -static inline Bac_Ntk_t * Bac_NtkCopyNtk(Bac_Man_t * pNew, Bac_Ntk_t * p) { return Bac_ManNtk(pNew, Bac_NtkCopy(p)); } -static inline void Bac_NtkSetCopy( Bac_Ntk_t * p, int i ) { assert(p->iCopy == -1); p->iCopy = i; } - -static inline int Bac_NtkObjNum( Bac_Ntk_t * p ) { return Vec_StrSize(&p->vType); } -static inline int Bac_NtkObjNumAlloc( Bac_Ntk_t * p ) { return Vec_StrCap(&p->vType); } -static inline int Bac_NtkPiNum( Bac_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); } -static inline int Bac_NtkPoNum( Bac_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); } -static inline int Bac_NtkPioNum( Bac_Ntk_t * p ) { return Bac_NtkPiNum(p) + Bac_NtkPoNum(p); } -static inline int Bac_NtkPiNumAlloc( Bac_Ntk_t * p ) { return Vec_IntCap(&p->vInputs); } -static inline int Bac_NtkPoNumAlloc( Bac_Ntk_t * p ) { return Vec_IntCap(&p->vOutputs); } -static inline int Bac_NtkBiNum( Bac_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BI); } -static inline int Bac_NtkBoNum( Bac_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BO); } -static inline int Bac_NtkCiNum( Bac_Ntk_t * p ) { return Bac_NtkPiNum(p) + Bac_NtkBoNum(p); } -static inline int Bac_NtkCoNum( Bac_Ntk_t * p ) { return Bac_NtkPoNum(p) + Bac_NtkBiNum(p); } -static inline int Bac_NtkBoxNum( Bac_Ntk_t * p ) { return Bac_NtkObjNum(p) - Vec_StrCountSmallerLit(&p->vType, (char)BAC_OBJ_BOX); } -static inline int Bac_NtkPrimNum( Bac_Ntk_t * p ) { return Vec_StrCountLargerLit(&p->vType, (char)BAC_OBJ_BOX); } -static inline int Bac_NtkUserNum( Bac_Ntk_t * p ) { return Vec_StrCountEntryLit(&p->vType, (char)BAC_OBJ_BOX); } - -static inline int Bac_NtkPi( Bac_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInputs, i); } -static inline int Bac_NtkPo( Bac_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vOutputs, i); } -static inline char * Bac_NtkStr( Bac_Ntk_t * p, int i ) { return Bac_ManStr(p->pDesign, i); } -static inline Bac_Ntk_t * Bac_NtkHostNtk( Bac_Ntk_t * p ) { return p->iBoxNtk > 0 ? Bac_ManNtk(p->pDesign, p->iBoxNtk) : NULL; } -static inline int Bac_NtkHostObj( Bac_Ntk_t * p ) { return p->iBoxObj; } -static inline void Bac_NtkSetHost( Bac_Ntk_t * p, int n, int i ) { assert(p->iBoxNtk == -1); p->iBoxNtk = n; p->iBoxObj = i; } - -static inline int Bac_InfoRange( int Beg, int End ) { return End > Beg ? End - Beg + 1 : Beg - End + 1; } -static inline int Bac_NtkInfoNum( Bac_Ntk_t * p ) { return Vec_IntSize(&p->vInfo)/3; } -static inline int Bac_NtkInfoNumAlloc( Bac_Ntk_t * p ) { return Vec_IntCap(&p->vInfo)/3; } -static inline int Bac_NtkInfoType( Bac_Ntk_t * p, int i ) { return Abc_Lit2Att2(Vec_IntEntry(&p->vInfo, 3*i)); } -static inline int Bac_NtkInfoName( Bac_Ntk_t * p, int i ) { return Abc_Lit2Var2(Vec_IntEntry(&p->vInfo, 3*i)); } -static inline int Bac_NtkInfoBeg( Bac_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInfo, 3*i+1); } -static inline int Bac_NtkInfoEnd( Bac_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInfo, 3*i+2); } -static inline int Bac_NtkInfoRange( Bac_Ntk_t * p, int i ) { int* a = Vec_IntEntryP(&p->vInfo, 3*i); return a[1]>=0 ? Bac_InfoRange( a[1], a[2] ) : 1; } -static inline int Bac_NtkInfoIndex( Bac_Ntk_t * p, int i, int j ) { int* a = Vec_IntEntryP(&p->vInfo, 3*i); assert(a[1]>=0); return a[1]vInfo, i); Vec_IntPushTwo(&p->vInfo, b, e); } -static inline void Bac_NtkSetInfoName( Bac_Ntk_t * p, int i, int n){ Vec_IntWriteEntry( &p->vInfo, 3*i, n ); } - -static inline void Bac_NtkStartNames( Bac_Ntk_t * p ) { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vName, Bac_NtkObjNumAlloc(p), 0); } -static inline void Bac_NtkStartFanouts( Bac_Ntk_t * p ) { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vFanout, Bac_NtkObjNumAlloc(p), 0); } -static inline void Bac_NtkStartCopies( Bac_Ntk_t * p ) { assert(Bac_NtkObjNumAlloc(p)); Vec_IntFill(&p->vCopy, Bac_NtkObjNumAlloc(p), -1); } -static inline void Bac_NtkFreeNames( Bac_Ntk_t * p ) { Vec_IntErase(&p->vName); } -static inline void Bac_NtkFreeFanouts( Bac_Ntk_t * p ) { Vec_IntErase(&p->vFanout); } -static inline void Bac_NtkFreeCopies( Bac_Ntk_t * p ) { Vec_IntErase(&p->vCopy); } -static inline int Bac_NtkHasNames( Bac_Ntk_t * p ) { return p->vName.pArray != NULL; } -static inline int Bac_NtkHasFanouts( Bac_Ntk_t * p ) { return p->vFanout.pArray != NULL; } -static inline int Bac_NtkHasCopies( Bac_Ntk_t * p ) { return p->vCopy.pArray != NULL; } - -static inline int Bac_TypeIsBox( Bac_ObjType_t Type ) { return Type >= BAC_OBJ_BOX && Type < BAC_BOX_UNKNOWN; } -static inline Bac_NameType_t Bac_NameType( int n ) { assert( n ); return (Bac_NameType_t)Abc_Lit2Att2( n ); } -static inline int Bac_CharIsDigit( char c ) { return c >= '0' && c <= '9'; } - -static inline Bac_ObjType_t Bac_ObjType( Bac_Ntk_t * p, int i ) { return (Bac_ObjType_t)Abc_Lit2Var((int)(unsigned char)Vec_StrEntry(&p->vType, i)); } -static inline int Bac_ObjIsPi( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_OBJ_PI; } -static inline int Bac_ObjIsPo( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_OBJ_PO; } -static inline int Bac_ObjIsPio( Bac_Ntk_t * p, int i ) { return Bac_ObjIsPi(p, i) || Bac_ObjIsPo(p, i); } -static inline int Bac_ObjIsBi( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_OBJ_BI; } -static inline int Bac_ObjIsBo( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_OBJ_BO; } -static inline int Bac_ObjIsBio( Bac_Ntk_t * p, int i ) { return Bac_ObjIsBi(p, i) || Bac_ObjIsBo(p, i); } -static inline int Bac_ObjIsBox( Bac_Ntk_t * p, int i ) { return Bac_TypeIsBox(Bac_ObjType(p, i)); } -static inline int Bac_ObjIsBoxUser( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_OBJ_BOX; } -static inline int Bac_ObjIsBoxPrim( Bac_Ntk_t * p, int i ) { return Bac_ObjIsBox(p, i) && !Bac_ObjIsBoxUser(p, i); } -static inline int Bac_ObjIsGate( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_BOX_GATE; } -static inline int Bac_ObjIsCi( Bac_Ntk_t * p, int i ) { return Bac_ObjIsPi(p, i) || Bac_ObjIsBo(p, i); } -static inline int Bac_ObjIsCo( Bac_Ntk_t * p, int i ) { return Bac_ObjIsPo(p, i) || Bac_ObjIsBi(p, i); } -static inline int Bac_ObjIsCio( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) < BAC_OBJ_BOX; } -static inline int Bac_ObjIsConst( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) >= BAC_BOX_CF && Bac_ObjType(p, i) <= BAC_BOX_CZ; } -static inline int Bac_ObjIsConstBin( Bac_Ntk_t * p, int i ) { return Bac_ObjType(p, i) == BAC_BOX_CF || Bac_ObjType(p, i) == BAC_BOX_CT; } - -static inline int Bac_ObjBit( Bac_Ntk_t * p, int i ) { assert(!Bac_ObjIsBox(p, i)); return Abc_LitIsCompl((int)Vec_StrEntry(&p->vType, i)); } -static inline void Bac_ObjSetBit( Bac_Ntk_t * p, int i ) { char *q = Vec_StrArray(&p->vType); assert(!Bac_ObjIsBox(p, i)); q[i] = (char)Abc_LitNot((int)q[i]); } -static inline int Bac_ObjFanin( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vFanin, i); } -static inline int Bac_ObjIndex( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsCio(p, i)); return Vec_IntEntry(&p->vIndex, i); } -static inline int Bac_ObjNameInt( Bac_Ntk_t * p, int i ) { assert(!Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vName, i); } -static inline int Bac_ObjName( Bac_Ntk_t * p, int i ) { return Bac_ObjIsCo(p, i) ? Bac_ObjNameInt(p, Bac_ObjFanin(p,i)) : Bac_ObjNameInt(p, i); } -static inline Bac_NameType_t Bac_ObjNameType( Bac_Ntk_t * p, int i ) { return Bac_NameType( Bac_ObjName(p, i) ); } -static inline int Bac_ObjNameId( Bac_Ntk_t * p, int i ) { return Abc_Lit2Var2( Bac_ObjName(p, i) ); } -static inline char * Bac_ObjNameStr( Bac_Ntk_t * p, int i ) { assert(Bac_ObjNameType(p, i) <= BAC_NAME_WORD); return Bac_NtkStr(p, Bac_ObjNameId(p, i)); } -static inline int Bac_ObjCopy( Bac_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vCopy, i); } -static inline int Bac_ObjFanout( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsCi(p, i)); return Vec_IntEntry(&p->vFanout, i); } -static inline int Bac_ObjNextFanout( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsCo(p, i)); return Vec_IntEntry(&p->vFanout, i); } -static inline void Bac_ObjSetFanout( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjIsCi(p, i)); Vec_IntSetEntry(&p->vFanout, i, x); } -static inline void Bac_ObjSetNextFanout( Bac_Ntk_t * p,int i,int x){ assert(Bac_ObjIsCo(p, i)); Vec_IntSetEntry(&p->vFanout, i, x); } -static inline void Bac_ObjCleanFanin( Bac_Ntk_t * p, int i ) { assert(Bac_ObjFanin(p, i) >= 0 && Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vFanin, i, -1); } -static inline void Bac_ObjSetFanin( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjFanin(p, i) == -1 && Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vFanin, i, x); } -static inline void Bac_ObjSetIndex( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjIndex(p, i) == -1); Vec_IntSetEntry( &p->vIndex, i, x ); } -static inline void Bac_ObjSetName( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjName(p, i) == 0 && !Bac_ObjIsCo(p, i)); Vec_IntSetEntry( &p->vName, i, x ); } -static inline void Bac_ObjSetCopy( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjCopy(p, i) == -1); Vec_IntSetEntry( &p->vCopy, i, x ); } -static inline int Bac_ObjGetConst( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsCi(p, i)); return Bac_ObjIsBo(p, i) && Bac_ObjIsConst(p, i-1) ? Bac_ObjType(p, i-1) : 0; } - -static inline int Bac_BoxBiNum( Bac_Ntk_t * p, int i ) { int s = i-1; assert(Bac_ObjIsBox(p, i)); while (--i >= 0 && Bac_ObjIsBi(p, i)) {} return s - i; } -static inline int Bac_BoxBoNum( Bac_Ntk_t * p, int i ) { int s = i+1; assert(Bac_ObjIsBox(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, i)) {} return i - s; } -static inline int Bac_BoxSize( Bac_Ntk_t * p, int i ) { return 1 + Bac_BoxBiNum(p, i) + Bac_BoxBoNum(p, i); } -static inline int Bac_BoxBi( Bac_Ntk_t * p, int b, int i ) { assert(Bac_ObjIsBox(p, b)); return b - 1 - i; } -static inline int Bac_BoxBo( Bac_Ntk_t * p, int b, int i ) { assert(Bac_ObjIsBox(p, b)); return b + 1 + i; } -//static inline int Bac_BoxBiBox( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsBi(p, i)); return i + 1 + Bac_ObjIndex(p, i); } -static inline int Bac_BoxBoBox( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsBo(p, i)); return i - 1 - Bac_ObjIndex(p, i); } -static inline int Bac_BoxFanin( Bac_Ntk_t * p, int b, int i ) { return Bac_ObjFanin(p, Bac_BoxBi(p, b, i)); } -static inline int Bac_BoxFaninBox( Bac_Ntk_t * p, int b, int i ) { return Bac_BoxBoBox(p, Bac_BoxFanin(p, b, i)); } -static inline int Bac_BoxBiRange( Bac_Ntk_t * p, int i ) { int s = i; assert(Bac_ObjIsBi(p, i) && !Bac_ObjBit(p, i)); while (--i >= 0 && Bac_ObjIsBi(p, i) && Bac_ObjBit(p, i)) {} return s - i; } -static inline int Bac_BoxBoRange( Bac_Ntk_t * p, int i ) { int s = i; assert(Bac_ObjIsBo(p, i) && !Bac_ObjBit(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, i) && Bac_ObjBit(p, i)) {} return i - s; } -static inline int Bac_ObjPiRange( Bac_Ntk_t * p, int i ) { int s = i; assert(Bac_ObjIsPi(p, i) && !Bac_ObjBit(p, i)); while (++i < Bac_NtkObjNum(p) && Bac_ObjIsPi(p, i) && Bac_ObjBit(p, i)) {} return i - s; } - -static inline int Bac_BoxNtkId( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsBox(p, i)); return Vec_IntEntry(&p->vFanin, i); } -static inline void Bac_BoxSetNtkId( Bac_Ntk_t * p, int i, int x ) { assert(Bac_ObjIsBox(p, i)&&Bac_ManNtkIsOk(p->pDesign, x));Vec_IntSetEntry(&p->vFanin, i, x);} -//static inline int Bac_BoxBiNtkId( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsBi(p, i)); return Bac_BoxNtkId(p, Bac_BoxBiBox(p, i)); } -static inline int Bac_BoxBoNtkId( Bac_Ntk_t * p, int i ) { assert(Bac_ObjIsBo(p, i)); return Bac_BoxNtkId(p, Bac_BoxBoBox(p, i)); } -static inline Bac_Ntk_t * Bac_BoxNtk( Bac_Ntk_t * p, int i ) { return Bac_ManNtk( p->pDesign, Bac_BoxNtkId(p, i) ); } -//static inline Bac_Ntk_t * Bac_BoxBiNtk( Bac_Ntk_t * p, int i ) { return Bac_ManNtk( p->pDesign, Bac_BoxBiNtkId(p, i) ); } -static inline Bac_Ntk_t * Bac_BoxBoNtk( Bac_Ntk_t * p, int i ) { return Bac_ManNtk( p->pDesign, Bac_BoxBoNtkId(p, i) ); } -static inline char * Bac_BoxNtkName( Bac_Ntk_t * p, int i ) { return Abc_NamStr( p->pDesign->pMods, Bac_BoxNtkId(p, i) ); } - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -#define Bac_ManForEachNtk( p, pNtk, i ) \ - for ( i = 1; (i <= Bac_ManNtkNum(p)) && (((pNtk) = Bac_ManNtk(p, i)), 1); i++ ) - -#define Bac_NtkForEachPi( p, iObj, i ) \ - for ( i = 0; (i < Bac_NtkPiNum(p)) && (((iObj) = Bac_NtkPi(p, i)), 1); i++ ) -#define Bac_NtkForEachPo( p, iObj, i ) \ - for ( i = 0; (i < Bac_NtkPoNum(p)) && (((iObj) = Bac_NtkPo(p, i)), 1); i++ ) -#define Bac_NtkForEachPoDriver( p, iObj, i ) \ - for ( i = 0; (i < Bac_NtkPoNum(p)) && (((iObj) = Bac_ObjFanin(p, Bac_NtkPo(p, i))), 1); i++ ) - -#define Bac_NtkForEachPiMain( p, iObj, i ) \ - for ( i = 0; (i < Bac_NtkPiNum(p)) && (((iObj) = Bac_NtkPi(p, i)), 1); i++ ) if ( Bac_ObjBit(p, iObj) ) {} else -#define Bac_NtkForEachPoMain( p, iObj, i ) \ - for ( i = 0; (i < Bac_NtkPoNum(p)) && (((iObj) = Bac_NtkPo(p, i)), 1); i++ ) if ( Bac_ObjBit(p, iObj) ) {} else - -#define Bac_NtkForEachObj( p, i ) if ( !Bac_ObjType(p, i) ) {} else \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) -#define Bac_NtkForEachObjType( p, Type, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)) && (((Type) = Bac_ObjType(p, i)), 1); i++ ) if ( !Type ) {} else - -#define Bac_NtkForEachBox( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBox(p, i) ) {} else -#define Bac_NtkForEachBoxUser( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBoxUser(p, i) ) {} else -#define Bac_NtkForEachBoxPrim( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBoxPrim(p, i) ) {} else - -#define Bac_NtkForEachCi( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCi(p, i) ) {} else -#define Bac_NtkForEachCo( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCo(p, i) ) {} else -#define Bac_NtkForEachCio( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsCio(p, i) ){} else - -#define Bac_NtkForEachBi( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBi(p, i) ){} else -#define Bac_NtkForEachBo( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBo(p, i) ){} else -#define Bac_NtkForEachBio( p, i ) \ - for ( i = 0; (i < Bac_NtkObjNum(p)); i++ ) if ( !Bac_ObjIsBio(p, i) ){} else - -#define Bac_BoxForEachBi( p, iBox, iTerm, i ) \ - for ( iTerm = iBox - 1, i = 0; iTerm >= 0 && Bac_ObjIsBi(p, iTerm); iTerm--, i++ ) -#define Bac_BoxForEachBo( p, iBox, iTerm, i ) \ - for ( iTerm = iBox + 1, i = 0; iTerm < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, iTerm); iTerm++, i++ ) -#define Bac_BoxForEachBiReverse( p, iBox, iTerm, i ) \ - for ( i = Bac_BoxBiNum(p, iBox), iTerm = iBox - i--; Bac_ObjIsBi(p, iTerm); iTerm++, i-- ) - -#define Bac_BoxForEachBiMain( p, iBox, iTerm, i ) \ - for ( iTerm = iBox - 1, i = 0; iTerm >= 0 && Bac_ObjIsBi(p, iTerm); iTerm--, i++ ) if ( Bac_ObjBit(p, iTerm) ) {} else -#define Bac_BoxForEachBoMain( p, iBox, iTerm, i ) \ - for ( iTerm = iBox + 1, i = 0; iTerm < Bac_NtkObjNum(p) && Bac_ObjIsBo(p, iTerm); iTerm++, i++ ) if ( Bac_ObjBit(p, iTerm) ) {} else - -#define Bac_BoxForEachFanin( p, iBox, iFanin, i ) \ - for ( i = 0; iBox - 1 - i >= 0 && Bac_ObjIsBi(p, iBox - 1 - i) && (((iFanin) = Bac_BoxFanin(p, iBox, i)), 1); i++ ) -#define Bac_BoxForEachFaninBox( p, iBox, iFanin, i ) \ - for ( i = 0; iBox - 1 - i >= 0 && Bac_ObjIsBi(p, iBox - 1 - i) && (((iFanin) = Bac_BoxFaninBox(p, iBox, i)), 1); i++ ) - -#define Bac_ObjForEachFanout( p, iCi, iCo ) \ - for ( iCo = Bac_ObjFanout(p, iCi); iCo; iCo = Bac_ObjNextFanout(p, iCo) ) -#define Bac_BoxForEachFanoutBox( p, iBox, iCo, iFanBox ) \ - for ( assert(Bac_BoxBoNum(p, iBox) == 1), iCo = Bac_ObjFanout(p, Bac_BoxBo(p, iBox, 0)); iCo && ((iFanBox = Bac_BoxBiBox(p, iCo)), 1); iCo = Bac_ObjNextFanout(p, iCo) ) - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Object APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Bac_ObjAlloc( Bac_Ntk_t * p, Bac_ObjType_t Type, int Fanin ) -{ - int iObj = Bac_NtkObjNum(p); - assert( iObj == Vec_IntSize(&p->vFanin) ); - if ( Type == BAC_OBJ_PI ) - Vec_IntPush( &p->vInputs, iObj ); - else if ( Type == BAC_OBJ_PO ) - Vec_IntPush( &p->vOutputs, iObj ); - Vec_StrPush( &p->vType, (char)Abc_Var2Lit(Type, 0) ); - Vec_IntPush( &p->vFanin, Fanin ); - return iObj; -} -static inline int Bac_ObjDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p, int i ) -{ - int iObj = Bac_ObjAlloc( pNew, Bac_ObjType(p, i), Bac_ObjIsBox(p, i) ? Bac_BoxNtkId(p, i) : -1 ); - if ( Bac_NtkHasNames(p) && Bac_NtkHasNames(pNew) && !Bac_ObjIsCo(p, i) ) - Bac_ObjSetName( pNew, iObj, Bac_ObjName(p, i) ); - Bac_ObjSetCopy( p, i, iObj ); - return iObj; -} -static inline int Bac_BoxAlloc( Bac_Ntk_t * p, Bac_ObjType_t Type, int nIns, int nOuts, int iNtk ) -{ - int i, iObj; - for ( i = nIns - 1; i >= 0; i-- ) - Bac_ObjAlloc( p, BAC_OBJ_BI, -1 ); - iObj = Bac_ObjAlloc( p, Type, iNtk ); - for ( i = 0; i < nOuts; i++ ) - Bac_ObjAlloc( p, BAC_OBJ_BO, -1 ); - return iObj; -} -static inline int Bac_BoxDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p, int iBox ) -{ - int i, iTerm, iBoxNew; - Bac_BoxForEachBiReverse( p, iBox, iTerm, i ) - Bac_ObjDup( pNew, p, iTerm ); - iBoxNew = Bac_ObjDup( pNew, p, iBox ); - if ( Bac_NtkHasNames(p) && Bac_NtkHasNames(pNew) && Bac_ObjName(p, iBox) ) - Bac_ObjSetName( pNew, iBoxNew, Bac_ObjName(p, iBox) ); - if ( Bac_BoxNtk(p, iBox) ) - Bac_BoxSetNtkId( pNew, iBoxNew, Bac_NtkCopy(Bac_BoxNtk(p, iBox)) ); - Bac_BoxForEachBo( p, iBox, iTerm, i ) - Bac_ObjDup( pNew, p, iTerm ); - return iBoxNew; -} -static inline void Bac_BoxDelete( Bac_Ntk_t * p, int iBox ) -{ - int iStart = iBox - Bac_BoxBiNum(p, iBox); - int i, iStop = iBox + Bac_BoxBoNum(p, iBox); - for ( i = iStart; i <= iStop; i++ ) - { - Vec_StrWriteEntry( &p->vType, i, (char)0 ); - Vec_IntWriteEntry( &p->vFanin, i, -1 ); - if ( Bac_NtkHasNames(p) ) - Vec_IntWriteEntry( &p->vName, i, 0 ); - if ( Bac_NtkHasFanouts(p) ) - Vec_IntWriteEntry( &p->vFanout, i, 0 ); - } -} -static inline void Bac_BoxReplace( Bac_Ntk_t * p, int iBox, int * pArray, int nSize ) -{ - extern void Bac_NtkUpdateFanout( Bac_Ntk_t * p, int iOld, int iNew ); - int i, Limit = Bac_BoxBoNum(p, iBox); - assert( Limit == nSize ); - for ( i = 0; i < Limit; i++ ) - Bac_NtkUpdateFanout( p, Bac_BoxBo(p, iBox, i), pArray[i] ); -} - - -static inline Vec_Int_t * Bac_BoxCollectRanges( Bac_Ntk_t * p, int iBox ) -{ - static Vec_Int_t Bits, * vBits = &Bits; - static int pArray[10]; int i, iTerm; - assert( !Bac_ObjIsBoxUser(p, iBox) ); - // initialize array - vBits->pArray = pArray; - vBits->nSize = 0; - vBits->nCap = 10; - // iterate through inputs - Bac_BoxForEachBiMain( p, iBox, iTerm, i ) - Vec_IntPush( vBits, Bac_BoxBiRange(p, iTerm) ); - // iterate through outputs - Bac_BoxForEachBoMain( p, iBox, iTerm, i ) - Vec_IntPush( vBits, Bac_BoxBoRange(p, iTerm) ); - assert( Vec_IntSize(vBits) < 10 ); - //Vec_IntPrint( vBits ); - return vBits; -} - -/**Function************************************************************* - - Synopsis [Prints vector.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Vec_StrPrint( Vec_Str_t * p, int fInt ) -{ - int i; - for ( i = 0; i < p->nSize; i++ ) - if ( fInt ) - printf( "%d ", (int)p->pArray[i] ); - else - printf( "%c ", p->pArray[i] ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Network APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Bac_NtkAlloc( Bac_Ntk_t * pNew, int NameId, int nIns, int nOuts, int nObjs ) -{ - int NtkId, fFound; - assert( pNew->pDesign != NULL ); - assert( Bac_NtkPiNum(pNew) == 0 ); - assert( Bac_NtkPoNum(pNew) == 0 ); - pNew->NameId = NameId; - pNew->iCopy = -1; - pNew->iBoxNtk = -1; - pNew->iBoxObj = -1; - Vec_IntGrow( &pNew->vInputs, nIns ); - Vec_IntGrow( &pNew->vOutputs, nOuts ); - Vec_StrGrow( &pNew->vType, nObjs ); - Vec_IntGrow( &pNew->vFanin, nObjs ); - // check if the network is unique - NtkId = Abc_NamStrFindOrAdd( pNew->pDesign->pMods, Bac_NtkStr(pNew, NameId), &fFound ); - if ( fFound ) - printf( "Network with name %s already exists.\n", Bac_NtkStr(pNew, NameId) ); - else - assert( NtkId == Bac_NtkId(pNew) ); -} -static inline void Bac_NtkDup( Bac_Ntk_t * pNew, Bac_Ntk_t * p ) -{ - int i, iObj; - assert( pNew != p ); - Bac_NtkAlloc( pNew, Bac_NtkNameId(p), Bac_NtkPiNum(p), Bac_NtkPoNum(p), Bac_NtkObjNum(p) ); - if ( Vec_IntSize(&p->vInfo) ) - Vec_IntAppend( &pNew->vInfo, &p->vInfo ); - Bac_NtkStartCopies( p ); - if ( Bac_NtkHasNames(p) ) - Bac_NtkStartNames( pNew ); - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjDup( pNew, p, iObj ); - Bac_NtkForEachBox( p, iObj ) - Bac_BoxDup( pNew, p, iObj ); - Bac_NtkForEachPo( p, iObj, i ) - Bac_ObjDup( pNew, p, iObj ); - Bac_NtkForEachCo( p, iObj ) - Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iObj), Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) ); - //Bac_NtkFreeCopies( p ); // needed for name transfer and host ntk - assert( Bac_NtkObjNum(pNew) == Bac_NtkObjNumAlloc(pNew) ); -} -static inline void Bac_NtkDupUserBoxes( Bac_Ntk_t * pNew, Bac_Ntk_t * p ) -{ - int i, iObj; - assert( pNew != p ); - Bac_NtkAlloc( pNew, Bac_NtkNameId(p), Bac_NtkPiNum(p), Bac_NtkPoNum(p), Bac_NtkObjNum(p) + 3*Bac_NtkCoNum(p) ); - if ( Vec_IntSize(&p->vInfo) ) - Vec_IntAppend( &pNew->vInfo, &p->vInfo ); - Bac_NtkStartCopies( p ); - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjDup( pNew, p, iObj ); - Bac_NtkForEachPo( p, iObj, i ) - Bac_ObjDup( pNew, p, iObj ); - Bac_NtkForEachBoxUser( p, iObj ) - Bac_BoxDup( pNew, p, iObj ); - // connect feed-throughs - Bac_NtkForEachCo( p, iObj ) - if ( Bac_ObjCopy(p, iObj) >= 0 && Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) >= 0 ) - Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iObj), Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) ); -} -static inline void Bac_NtkMoveNames( Bac_Ntk_t * pNew, Bac_Ntk_t * p ) -{ - int i, iBox, iObj; - assert( Bac_NtkHasNames(p) ); - assert( !Bac_NtkHasNames(pNew) ); - Bac_NtkStartNames( pNew ); - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjSetName( pNew, Bac_ObjCopy(p, iObj), Bac_ObjName(p, iObj) ); - Bac_NtkForEachBoxUser( p, iBox ) - { - Bac_ObjSetName( pNew, Bac_ObjCopy(p, iBox), Bac_ObjName(p, iBox) ); - Bac_BoxForEachBo( p, iBox, iObj, i ) - Bac_ObjSetName( pNew, Bac_ObjCopy(p, iObj), Bac_ObjName(p, iObj) ); - } - Bac_NtkForEachBoxUser( p, iBox ) - Bac_BoxForEachBi( p, iBox, iObj, i ) - if ( !Bac_ObjName(pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj))) ) - Bac_ObjSetName( pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj)), Bac_ObjName(p, iObj) ); - Bac_NtkForEachPo( p, iObj, i ) - if ( !Bac_ObjName(pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj))) ) - Bac_ObjSetName( pNew, Bac_ObjFanin(pNew, Bac_ObjCopy(p, iObj)), Bac_ObjName(p, iObj) ); -} - -static inline void Bac_NtkFree( Bac_Ntk_t * p ) -{ - Vec_IntErase( &p->vInputs ); - Vec_IntErase( &p->vOutputs ); - Vec_IntErase( &p->vInfo ); - Vec_StrErase( &p->vType ); - Vec_IntErase( &p->vFanin ); - Vec_IntErase( &p->vIndex ); - Vec_IntErase( &p->vName ); - Vec_IntErase( &p->vFanout ); - Vec_IntErase( &p->vCopy ); - Vec_IntErase( &p->vArray ); - Vec_IntErase( &p->vArray2 ); -} -static inline int Bac_NtkMemory( Bac_Ntk_t * p ) -{ - int nMem = sizeof(Bac_Ntk_t); - nMem += (int)Vec_IntMemory(&p->vInputs); - nMem += (int)Vec_IntMemory(&p->vOutputs); - nMem += (int)Vec_IntMemory(&p->vInfo); - nMem += (int)Vec_StrMemory(&p->vType); - nMem += (int)Vec_IntMemory(&p->vFanin); - nMem += (int)Vec_IntMemory(&p->vIndex); - nMem += (int)Vec_IntMemory(&p->vName); - nMem += (int)Vec_IntMemory(&p->vFanout); - nMem += (int)Vec_IntMemory(&p->vCopy); - return nMem; -} -static inline void Bac_NtkPrintStats( Bac_Ntk_t * p ) -{ - printf( "pi =%5d ", Bac_NtkPiNum(p) ); - printf( "pi =%5d ", Bac_NtkPoNum(p) ); - printf( "box =%6d ", Bac_NtkBoxNum(p) ); - printf( "clp =%7d ", p->Count ); - printf( "obj =%7d ", Bac_NtkObjNum(p) ); - printf( "%s ", Bac_NtkName(p) ); - if ( Bac_NtkHostNtk(p) ) - printf( "-> %s", Bac_NtkName(Bac_NtkHostNtk(p)) ); - printf( "\n" ); -} -static inline void Bac_NtkDeriveIndex( Bac_Ntk_t * p ) -{ - int i, iObj, iTerm; - Vec_IntFill( &p->vIndex, Bac_NtkObjNum(p), -1 ); - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjSetIndex( p, iObj, i ); - Bac_NtkForEachPo( p, iObj, i ) - Bac_ObjSetIndex( p, iObj, i ); - Bac_NtkForEachBox( p, iObj ) - { - Bac_BoxForEachBi( p, iObj, iTerm, i ) - Bac_ObjSetIndex( p, iTerm, i ); - Bac_BoxForEachBo( p, iObj, iTerm, i ) - Bac_ObjSetIndex( p, iTerm, i ); - } -} -static inline void Bac_NtkPrint( Bac_Ntk_t * p ) -{ - int i, Type, Value, Beg, End; - printf( "Interface (%d):\n", Bac_NtkInfoNum(p) ); - Vec_IntForEachEntryTriple( &p->vInfo, Value, Beg, End, i ) - { - printf( "%6d : ", i ); - printf( "Type =%3d ", Bac_NtkInfoType(p, i/3) ); - if ( Beg >= 0 ) - printf( "[%d:%d] ", End, Beg ); - else - printf( " " ); - printf( "Name =%3d ", Bac_NtkInfoName(p, i/3) ); - if ( Bac_NtkInfoName(p, i/3) ) - printf( "%s", Bac_NtkStr( p, Bac_NtkInfoName(p, i/3) ) ); - printf( "\n" ); - } - printf( "Objects (%d):\n", Bac_NtkObjNum(p) ); - Bac_NtkForEachObjType( p, Type, i ) - { - printf( "%6d : ", i ); - printf( "Type =%3d ", Type ); - if ( Bac_ObjIsCo(p, i) ) - printf( "Fanin =%6d ", Bac_ObjFanin(p, i) ); - else if ( Bac_NtkHasNames(p) && Bac_ObjName(p, i) ) - { - printf( "Name =%6d(%d) ", Bac_ObjNameId(p, i), Bac_ObjNameType(p, i) ); - if ( Bac_ObjNameType(p, i) <= BAC_NAME_WORD ) - printf( "%s", Bac_ObjNameStr(p, i) ); - } - printf( "\n" ); - } -} - - -/**Function************************************************************* - - Synopsis [Manager APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Bac_Man_t * Bac_ManAlloc( char * pFileName, int nNtks ) -{ - extern void Bac_ManSetupTypes( char ** pNames, char ** pSymbs ); - Bac_Ntk_t * pNtk; int i; - Bac_Man_t * pNew = ABC_CALLOC( Bac_Man_t, 1 ); - pNew->pName = Extra_FileDesignName( pFileName ); - pNew->pSpec = Abc_UtilStrsav( pFileName ); - pNew->pStrs = Abc_NamStart( 1000, 24 ); - pNew->pMods = Abc_NamStart( 1000, 24 ); - pNew->iRoot = 1; - pNew->nNtks = nNtks; - pNew->pNtks = ABC_CALLOC( Bac_Ntk_t, pNew->nNtks + 1 ); - Bac_ManForEachNtk( pNew, pNtk, i ) - pNtk->pDesign = pNew; - Bac_ManSetupTypes( pNew->pPrimNames, pNew->pPrimSymbs ); - return pNew; -} -static inline Bac_Man_t * Bac_ManStart( Bac_Man_t * p, int nNtks ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_Man_t * pNew = ABC_CALLOC( Bac_Man_t, 1 ); - pNew->pName = Abc_UtilStrsav( Bac_ManName(p) ); - pNew->pSpec = Abc_UtilStrsav( Bac_ManSpec(p) ); - pNew->pStrs = Abc_NamRef( p->pStrs ); - pNew->pMods = Abc_NamStart( 1000, 24 ); - pNew->iRoot = 1; - pNew->nNtks = nNtks; - pNew->pNtks = ABC_CALLOC( Bac_Ntk_t, nNtks + 1 ); - Bac_ManForEachNtk( pNew, pNtk, i ) - pNtk->pDesign = pNew; - return pNew; -} -static inline Bac_Man_t * Bac_ManDup( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk, * pHost; int i; - Bac_Man_t * pNew = Bac_ManStart( p, Bac_ManNtkNum(p) ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkSetCopy( pNtk, i ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkDup( Bac_NtkCopyNtk(pNew, pNtk), pNtk ); - Bac_ManForEachNtk( p, pNtk, i ) - if ( (pHost = Bac_NtkHostNtk(pNtk)) ) - Bac_NtkSetHost( Bac_NtkCopyNtk(pNew, pNtk), Bac_NtkCopy(pHost), Bac_ObjCopy(pHost, Bac_NtkHostObj(pNtk)) ); - return pNew; -} -static inline Bac_Man_t * Bac_ManDupUserBoxes( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk, * pHost; int i; - Bac_Man_t * pNew = Bac_ManStart( p, Bac_ManNtkNum(p) ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkSetCopy( pNtk, i ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkDupUserBoxes( Bac_NtkCopyNtk(pNew, pNtk), pNtk ); - Bac_ManForEachNtk( p, pNtk, i ) - if ( (pHost = Bac_NtkHostNtk(pNtk)) ) - Bac_NtkSetHost( Bac_NtkCopyNtk(pNew, pNtk), Bac_NtkCopy(pHost), Bac_ObjCopy(pHost, Bac_NtkHostObj(pNtk)) ); - return pNew; -} -static inline void Bac_ManMoveNames( Bac_Man_t * pNew, Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkMoveNames( Bac_NtkCopyNtk(pNew, pNtk), pNtk ); -} - - -static inline void Bac_ManFree( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkFree( pNtk ); - Vec_IntErase( &p->vBuf2LeafNtk ); - Vec_IntErase( &p->vBuf2LeafObj ); - Vec_IntErase( &p->vBuf2RootNtk ); - Vec_IntErase( &p->vBuf2RootObj ); - Abc_NamDeref( p->pStrs ); - Abc_NamDeref( p->pMods ); - ABC_FREE( p->pName ); - ABC_FREE( p->pSpec ); - ABC_FREE( p->pNtks ); - ABC_FREE( p ); -} -static inline int Bac_ManMemory( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - int nMem = sizeof(Bac_Man_t); - if ( p->pName ) - nMem += (int)strlen(p->pName); - if ( p->pSpec ) - nMem += (int)strlen(p->pSpec); - nMem += Abc_NamMemUsed(p->pStrs); - nMem += Abc_NamMemUsed(p->pMods); - Bac_ManForEachNtk( p, pNtk, i ) - nMem += Bac_NtkMemory( pNtk ); - return nMem; -} -static inline int Bac_ManObjNum( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i, Count = 0; - Bac_ManForEachNtk( p, pNtk, i ) - Count += Bac_NtkObjNum(pNtk); - return Count; -} -static inline int Bac_ManNodeNum( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i, Count = 0; - Bac_ManForEachNtk( p, pNtk, i ) - Count += Bac_NtkBoxNum( pNtk ); - return Count; -} -static inline int Bac_ManBoxNum_rec( Bac_Ntk_t * p ) -{ - int iObj, Counter = 0; - if ( p->Count >= 0 ) - return p->Count; - Bac_NtkForEachBox( p, iObj ) - Counter += Bac_ObjIsBoxUser(p, iObj) ? Bac_ManBoxNum_rec( Bac_BoxNtk(p, iObj) ) : 1; - return (p->Count = Counter); -} -static inline int Bac_ManBoxNum( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - pNtk->Count = -1; - return Bac_ManBoxNum_rec( Bac_ManRoot(p) ); -} -static inline void Bac_ManPrintStats( Bac_Man_t * p, int nModules, int fVerbose ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_Ntk_t * pRoot = Bac_ManRoot( p ); - printf( "%-12s : ", Bac_ManName(p) ); - printf( "pi =%5d ", Bac_NtkPiNum(pRoot) ); - printf( "po =%5d ", Bac_NtkPoNum(pRoot) ); - printf( "pri =%4d ", Bac_ManPrimNum(p) ); - printf( "mod =%6d ", Bac_ManNtkNum(p) ); - printf( "box =%7d ", Bac_ManNodeNum(p) ); - printf( "obj =%7d ", Bac_ManObjNum(p) ); - printf( "mem =%6.3f MB", 1.0*Bac_ManMemory(p)/(1<<20) ); - printf( "\n" ); - Bac_ManBoxNum( p ); - Bac_ManForEachNtk( p, pNtk, i ) - { - if ( i == nModules+1 ) - break; - printf( "Module %5d : ", i ); - Bac_NtkPrintStats( pNtk ); - } -} - - - -/**Function************************************************************* - - Synopsis [Other APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Bac_ObjType_t Ptr_SopToType( char * pSop ) -{ - if ( !strcmp(pSop, " 0\n") ) return BAC_BOX_CF; - if ( !strcmp(pSop, " 1\n") ) return BAC_BOX_CT; - if ( !strcmp(pSop, "1 1\n") ) return BAC_BOX_BUF; - if ( !strcmp(pSop, "0 1\n") ) return BAC_BOX_INV; - if ( !strcmp(pSop, "11 1\n") ) return BAC_BOX_AND; - if ( !strcmp(pSop, "00 1\n") ) return BAC_BOX_NOR; - if ( !strcmp(pSop, "00 0\n") ) return BAC_BOX_OR; - if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return BAC_BOX_OR; - if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return BAC_BOX_OR; - if ( !strcmp(pSop, "01 1\n10 1\n") ) return BAC_BOX_XOR; - if ( !strcmp(pSop, "10 1\n01 1\n") ) return BAC_BOX_XOR; - if ( !strcmp(pSop, "11 1\n00 1\n") ) return BAC_BOX_XNOR; - if ( !strcmp(pSop, "00 1\n11 1\n") ) return BAC_BOX_XNOR; - if ( !strcmp(pSop, "10 1\n") ) return BAC_BOX_SHARP; - if ( !strcmp(pSop, "01 1\n") ) return BAC_BOX_SHARPL; - assert( 0 ); - return BAC_OBJ_NONE; -} -static inline char * Ptr_SopToTypeName( char * pSop ) -{ - if ( !strcmp(pSop, " 0\n") ) return "BAC_BOX_C0"; - if ( !strcmp(pSop, " 1\n") ) return "BAC_BOX_C1"; - if ( !strcmp(pSop, "1 1\n") ) return "BAC_BOX_BUF"; - if ( !strcmp(pSop, "0 1\n") ) return "BAC_BOX_INV"; - if ( !strcmp(pSop, "11 1\n") ) return "BAC_BOX_AND"; - if ( !strcmp(pSop, "00 1\n") ) return "BAC_BOX_NOR"; - if ( !strcmp(pSop, "00 0\n") ) return "BAC_BOX_OR"; - if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return "BAC_BOX_OR"; - if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return "BAC_BOX_OR"; - if ( !strcmp(pSop, "01 1\n10 1\n") ) return "BAC_BOX_XOR"; - if ( !strcmp(pSop, "10 1\n01 1\n") ) return "BAC_BOX_XOR"; - if ( !strcmp(pSop, "11 1\n00 1\n") ) return "BAC_BOX_XNOR"; - if ( !strcmp(pSop, "00 1\n11 1\n") ) return "BAC_BOX_XNOR"; - if ( !strcmp(pSop, "10 1\n") ) return "BAC_BOX_SHARP"; - if ( !strcmp(pSop, "01 1\n") ) return "BAC_BOX_SHARPL"; - assert( 0 ); - return NULL; -} -static inline char * Ptr_TypeToName( Bac_ObjType_t Type ) -{ - if ( Type == BAC_BOX_CF ) return "const0"; - if ( Type == BAC_BOX_CT ) return "const1"; - if ( Type == BAC_BOX_CX ) return "constX"; - if ( Type == BAC_BOX_CZ ) return "constZ"; - if ( Type == BAC_BOX_BUF ) return "buf"; - if ( Type == BAC_BOX_INV ) return "not"; - if ( Type == BAC_BOX_AND ) return "and"; - if ( Type == BAC_BOX_NAND ) return "nand"; - if ( Type == BAC_BOX_OR ) return "or"; - if ( Type == BAC_BOX_NOR ) return "nor"; - if ( Type == BAC_BOX_XOR ) return "xor"; - if ( Type == BAC_BOX_XNOR ) return "xnor"; - if ( Type == BAC_BOX_MUX ) return "mux"; - if ( Type == BAC_BOX_MAJ ) return "maj"; - if ( Type == BAC_BOX_SHARP ) return "sharp"; - if ( Type == BAC_BOX_SHARPL) return "sharpl"; - assert( 0 ); - return "???"; -} -static inline char * Ptr_TypeToSop( Bac_ObjType_t Type ) -{ - if ( Type == BAC_BOX_CF ) return " 0\n"; - if ( Type == BAC_BOX_CT ) return " 1\n"; - if ( Type == BAC_BOX_CX ) return " 0\n"; - if ( Type == BAC_BOX_CZ ) return " 0\n"; - if ( Type == BAC_BOX_BUF ) return "1 1\n"; - if ( Type == BAC_BOX_INV ) return "0 1\n"; - if ( Type == BAC_BOX_AND ) return "11 1\n"; - if ( Type == BAC_BOX_NAND ) return "11 0\n"; - if ( Type == BAC_BOX_OR ) return "00 0\n"; - if ( Type == BAC_BOX_NOR ) return "00 1\n"; - if ( Type == BAC_BOX_XOR ) return "01 1\n10 1\n"; - if ( Type == BAC_BOX_XNOR ) return "00 1\n11 1\n"; - if ( Type == BAC_BOX_SHARP ) return "10 1\n"; - if ( Type == BAC_BOX_SHARPL) return "01 1\n"; - if ( Type == BAC_BOX_MUX ) return "11- 1\n0-1 1\n"; - if ( Type == BAC_BOX_MAJ ) return "11- 1\n1-1 1\n-11 1\n"; - assert( 0 ); - return "???"; -} - -/*=== bacCom.c ===============================================================*/ -extern void Abc_FrameImportPtr( Vec_Ptr_t * vPtr ); -extern Vec_Ptr_t * Abc_FrameExportPtr(); - -/*=== bacBlast.c =============================================================*/ -extern int Bac_NtkBuildLibrary( Bac_Man_t * p ); -extern Gia_Man_t * Bac_ManExtract( Bac_Man_t * p, int fBuffers, int fVerbose ); -extern Bac_Man_t * Bac_ManInsertGia( Bac_Man_t * p, Gia_Man_t * pGia ); -extern void * Bac_ManInsertAbc( Bac_Man_t * p, void * pAbc ); -/*=== bacCba.c ===============================================================*/ -extern Bac_Man_t * Bac_ManReadBac( char * pFileName ); -extern void Bac_ManWriteBac( char * pFileName, Bac_Man_t * p ); -/*=== bacNtk.c ===============================================================*/ -extern char * Bac_NtkGenerateName( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vBits ); -extern Bac_ObjType_t Bac_NameToType( char * pName ); -extern Vec_Int_t * Bac_NameToRanges( char * pName ); -extern void Bac_NtkUpdateFanout( Bac_Ntk_t * p, int iOld, int iNew ); -extern void Bac_ManDeriveFanout( Bac_Man_t * p ); -//extern void Bac_ManAssignInternNames( Bac_Man_t * p ); -extern void Bac_ManAssignInternWordNames( Bac_Man_t * p ); -extern Bac_Man_t * Bac_ManCollapse( Bac_Man_t * p ); -extern void Bac_ManSetupTypes( char ** pNames, char ** pSymbs ); -/*=== bacPtr.c ===============================================================*/ -extern void Bac_PtrFree( Vec_Ptr_t * vDes ); -extern int Bac_PtrMemory( Vec_Ptr_t * vDes ); -extern void Bac_PtrDumpBlif( char * pFileName, Vec_Ptr_t * vDes ); -extern void Bac_PtrDumpVerilog( char * pFileName, Vec_Ptr_t * vDes ); -extern Vec_Ptr_t * Bac_PtrTransformTest( Vec_Ptr_t * vDes ); -/*=== bacPtrAbc.c ============================================================*/ -extern Bac_Man_t * Bac_PtrTransformToCba( Vec_Ptr_t * vDes ); -extern Vec_Ptr_t * Bac_PtrDeriveFromCba( Bac_Man_t * p ); -/*=== bacPrsBuild.c ==========================================================*/ -extern Bac_Man_t * Psr_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes ); -/*=== bacReadBlif.c ==========================================================*/ -extern Vec_Ptr_t * Psr_ManReadBlif( char * pFileName ); -/*=== bacReadSmt.c ===========================================================*/ -extern Vec_Ptr_t * Psr_ManReadSmt( char * pFileName ); -/*=== bacReadVer.c ===========================================================*/ -extern Vec_Ptr_t * Psr_ManReadVerilog( char * pFileName ); -/*=== bacWriteBlif.c =========================================================*/ -extern void Psr_ManWriteBlif( char * pFileName, Vec_Ptr_t * p ); -extern void Bac_ManWriteBlif( char * pFileName, Bac_Man_t * p ); -/*=== bacWriteVer.c ==========================================================*/ -extern void Psr_ManWriteVerilog( char * pFileName, Vec_Ptr_t * p ); -extern void Bac_ManWriteVerilog( char * pFileName, Bac_Man_t * p, int fUseAssign ); - -ABC_NAMESPACE_HEADER_END - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/base/bac/bacBac.c b/src/base/bac/bacBac.c deleted file mode 100644 index 94c52fdb9..000000000 --- a/src/base/bac/bacBac.c +++ /dev/null @@ -1,298 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacBac.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacBac.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - - -/**Function************************************************************* - - Synopsis [Read CBA.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int BacManReadBacLine( Vec_Str_t * vOut, int * pPos, char * pBuffer, char * pLimit ) -{ - char c; - while ( (c = Vec_StrEntry(vOut, (*pPos)++)) != '\n' && pBuffer < pLimit ) - *pBuffer++ = c; - *pBuffer = 0; - return pBuffer < pLimit; -} -int BacManReadBacNameAndNums( char * pBuffer, int * Num1, int * Num2, int * Num3, int * Num4 ) -{ - *Num1 = *Num2 = *Num3 = *Num4 = -1; - // read name - while ( *pBuffer && *pBuffer != ' ' ) - pBuffer++; - if ( !*pBuffer ) - return 0; - assert( *pBuffer == ' ' ); - *pBuffer = 0; - // read Num1 - *Num1 = atoi(++pBuffer); - while ( *pBuffer && *pBuffer != ' ' ) - pBuffer++; - if ( !*pBuffer ) - return 0; - // read Num2 - assert( *pBuffer == ' ' ); - *Num2 = atoi(++pBuffer); - while ( *pBuffer && *pBuffer != ' ' ) - pBuffer++; - if ( !*pBuffer ) - return 1; - // read Num3 - assert( *pBuffer == ' ' ); - *Num3 = atoi(++pBuffer); - while ( *pBuffer && *pBuffer != ' ' ) - pBuffer++; - if ( !*pBuffer ) - return 1; - // read Num4 - assert( *pBuffer == ' ' ); - *Num4 = atoi(++pBuffer); - return 1; -} -void Bac_ManReadBacVecStr( Vec_Str_t * vOut, int * pPos, Vec_Str_t * p, int nSize ) -{ - memcpy( Vec_StrArray(p), Vec_StrArray(vOut) + *pPos, (size_t)nSize ); - *pPos += nSize; - p->nSize = nSize; - assert( Vec_StrSize(p) == Vec_StrCap(p) ); -} -void Bac_ManReadBacVecInt( Vec_Str_t * vOut, int * pPos, Vec_Int_t * p, int nSize ) -{ - memcpy( Vec_IntArray(p), Vec_StrArray(vOut) + *pPos, (size_t)nSize ); - *pPos += nSize; - p->nSize = nSize / 4; - assert( Vec_IntSize(p) == Vec_IntCap(p) ); -} -void Bac_ManReadBacNtk( Vec_Str_t * vOut, int * pPos, Bac_Ntk_t * pNtk ) -{ - int i, Type; - //char * pName; int iObj, NameId; - Bac_ManReadBacVecStr( vOut, pPos, &pNtk->vType, Bac_NtkObjNumAlloc(pNtk) ); - Bac_ManReadBacVecInt( vOut, pPos, &pNtk->vFanin, 4 * Bac_NtkObjNumAlloc(pNtk) ); - Bac_ManReadBacVecInt( vOut, pPos, &pNtk->vInfo, 12 * Bac_NtkInfoNumAlloc(pNtk) ); - Bac_NtkForEachObjType( pNtk, Type, i ) - { - if ( Type == BAC_OBJ_PI ) - Vec_IntPush( &pNtk->vInputs, i ); - if ( Type == BAC_OBJ_PO ) - Vec_IntPush( &pNtk->vOutputs, i ); - } - assert( Bac_NtkPiNum(pNtk) == Bac_NtkPiNumAlloc(pNtk) ); - assert( Bac_NtkPoNum(pNtk) == Bac_NtkPoNumAlloc(pNtk) ); - assert( Bac_NtkObjNum(pNtk) == Bac_NtkObjNumAlloc(pNtk) ); - assert( Bac_NtkInfoNum(pNtk) == Bac_NtkInfoNumAlloc(pNtk) ); -/* - // read input/output/box names - Bac_NtkForEachPiMain( pNtk, iObj, i ) - { - pName = Vec_StrEntryP( vOut, Pos ); - NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); - Pos += strlen(pName) + 1; - } - Bac_NtkForEachPoMain( pNtk, iObj, i ) - { - pName = Vec_StrEntryP( vOut, Pos ); - NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); - Pos += strlen(pName) + 1; - } - Bac_NtkForEachBox( pNtk, iObj ) - { - pName = Vec_StrEntryP( vOut, Pos ); - NameId = Abc_NamStrFindOrAdd( p->pStrs, pName, NULL ); - Pos += strlen(pName) + 1; - } -*/ -} -Bac_Man_t * Bac_ManReadBacInt( Vec_Str_t * vOut ) -{ - Bac_Man_t * p; - Bac_Ntk_t * pNtk; - char Buffer[1000] = "#"; - int i, NameId, Pos = 0, nNtks, Num1, Num2, Num3, Num4; - while ( Buffer[0] == '#' ) - if ( !BacManReadBacLine(vOut, &Pos, Buffer, Buffer+1000) ) - return NULL; - if ( !BacManReadBacNameAndNums(Buffer, &nNtks, &Num2, &Num3, &Num4) ) - return NULL; - // start manager - assert( nNtks > 0 ); - p = Bac_ManAlloc( Buffer, nNtks ); - // start networks - Bac_ManForEachNtk( p, pNtk, i ) - { - if ( !BacManReadBacLine(vOut, &Pos, Buffer, Buffer+1000) ) - { - Bac_ManFree( p ); - return NULL; - } - if ( !BacManReadBacNameAndNums(Buffer, &Num1, &Num2, &Num3, &Num4) ) - { - Bac_ManFree( p ); - return NULL; - } - assert( Num1 >= 0 && Num2 >= 0 && Num3 >= 0 ); - NameId = Abc_NamStrFindOrAdd( p->pStrs, Buffer, NULL ); - Bac_NtkAlloc( pNtk, NameId, Num1, Num2, Num3 ); - Vec_IntFill( &pNtk->vInfo, 3 * Num4, -1 ); - } - // read networks - Bac_ManForEachNtk( p, pNtk, i ) - Bac_ManReadBacNtk( vOut, &Pos, pNtk ); - assert( Bac_ManNtkNum(p) == nNtks ); - assert( Pos == Vec_StrSize(vOut) ); - return p; -} -Bac_Man_t * Bac_ManReadBac( char * pFileName ) -{ - Bac_Man_t * p; - FILE * pFile; - Vec_Str_t * vOut; - int nFileSize; - pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - printf( "Cannot open file \"%s\" for reading.\n", pFileName ); - return NULL; - } - // get the file size, in bytes - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - rewind( pFile ); - // load the contents - vOut = Vec_StrAlloc( nFileSize ); - vOut->nSize = vOut->nCap; - assert( nFileSize == Vec_StrSize(vOut) ); - nFileSize = fread( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile ); - assert( nFileSize == Vec_StrSize(vOut) ); - fclose( pFile ); - // read the networks - p = Bac_ManReadBacInt( vOut ); - if ( p != NULL ) - { - ABC_FREE( p->pSpec ); - p->pSpec = Abc_UtilStrsav( pFileName ); - } - Vec_StrFree( vOut ); - return p; -} - -/**Function************************************************************* - - Synopsis [Write CBA.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_ManWriteBacNtk( Vec_Str_t * vOut, Bac_Ntk_t * pNtk ) -{ - //char * pName; int iObj, NameId; - Vec_StrPushBuffer( vOut, (char *)Vec_StrArray(&pNtk->vType), Bac_NtkObjNum(pNtk) ); - Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vFanin), 4 * Bac_NtkObjNum(pNtk) ); - Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vInfo), 12 * Bac_NtkInfoNum(pNtk) ); -/* - // write input/output/box names - Bac_NtkForEachPiMain( pNtk, iObj, i ) - { - pName = Bac_ObjNameStr( pNtk, iObj ); - Vec_StrPrintStr( vOut, pName ); - Vec_StrPush( vOut, '\0' ); - } - Bac_NtkForEachPoMain( pNtk, iObj, i ) - { - pName = Bac_ObjNameStr( pNtk, iObj ); - Vec_StrPrintStr( vOut, pName ); - Vec_StrPush( vOut, '\0' ); - } - Bac_NtkForEachBox( pNtk, iObj ) - { - pName = Bac_ObjNameStr( pNtk, iObj ); - Vec_StrPrintStr( vOut, pName ); - Vec_StrPush( vOut, '\0' ); - } -*/ -} -void Bac_ManWriteBacInt( Vec_Str_t * vOut, Bac_Man_t * p ) -{ - char Buffer[1000]; - Bac_Ntk_t * pNtk; int i; - sprintf( Buffer, "# Design \"%s\" written by ABC on %s\n", Bac_ManName(p), Extra_TimeStamp() ); - Vec_StrPrintStr( vOut, Buffer ); - // write short info - sprintf( Buffer, "%s %d \n", Bac_ManName(p), Bac_ManNtkNum(p) ); - Vec_StrPrintStr( vOut, Buffer ); - Bac_ManForEachNtk( p, pNtk, i ) - { - sprintf( Buffer, "%s %d %d %d %d \n", Bac_NtkName(pNtk), - Bac_NtkPiNum(pNtk), Bac_NtkPoNum(pNtk), Bac_NtkObjNum(pNtk), Bac_NtkInfoNum(pNtk) ); - Vec_StrPrintStr( vOut, Buffer ); - } - Bac_ManForEachNtk( p, pNtk, i ) - Bac_ManWriteBacNtk( vOut, pNtk ); -} -void Bac_ManWriteBac( char * pFileName, Bac_Man_t * p ) -{ - Vec_Str_t * vOut; - assert( p->pMioLib == NULL ); - vOut = Vec_StrAlloc( 10000 ); - Bac_ManWriteBacInt( vOut, p ); - if ( Vec_StrSize(vOut) > 0 ) - { - FILE * pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - printf( "Cannot open file \"%s\" for writing.\n", pFileName ); - else - { - fwrite( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile ); - fclose( pFile ); - } - } - Vec_StrFree( vOut ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacBlast.c b/src/base/bac/bacBlast.c deleted file mode 100644 index f18436487..000000000 --- a/src/base/bac/bacBlast.c +++ /dev/null @@ -1,587 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacBlast.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Bit-blasting of the netlist.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacBlast.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.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 - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_ManPrepareGates( Bac_Man_t * p ) -{ - Dec_Graph_t ** ppGraphs; int i; - if ( p->pMioLib == NULL ) - return; - ppGraphs = ABC_CALLOC( Dec_Graph_t *, Abc_NamObjNumMax(p->pMods) ); - for ( i = 1; i < Abc_NamObjNumMax(p->pMods); i++ ) - { - char * pGateName = Abc_NamStr( p->pMods, i ); - Mio_Gate_t * pGate = Mio_LibraryReadGateByName( (Mio_Library_t *)p->pMioLib, pGateName, NULL ); - if ( pGate != NULL ) - ppGraphs[i] = Dec_Factor( Mio_GateReadSop(pGate) ); - } - assert( p->ppGraphs == NULL ); - p->ppGraphs = (void **)ppGraphs; -} -void Bac_ManUndoGates( Bac_Man_t * p ) -{ - int i; - if ( p->pMioLib == NULL ) - return; - for ( i = 1; i < Abc_NamObjNumMax(p->pMods); i++ ) - if ( p->ppGraphs[i] ) - Dec_GraphFree( (Dec_Graph_t *)p->ppGraphs[i] ); - ABC_FREE( p->ppGraphs ); -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ManAddBarbuf( Gia_Man_t * pNew, int iRes, Bac_Man_t * p, int iLNtk, int iLObj, int iRNtk, int iRObj, Vec_Int_t * vMap ) -{ - int iBufLit, iIdLit; - if ( iRes == 0 || iRes == 1 ) - return iRes; - assert( iRes > 0 ); - if ( vMap && Abc_Lit2Var(iRes) < Vec_IntSize(vMap) && (iIdLit = Vec_IntEntry(vMap, Abc_Lit2Var(iRes))) >= 0 && - Vec_IntEntry(&p->vBuf2LeafNtk, Abc_Lit2Var(iIdLit)) == iLNtk && Vec_IntEntry(&p->vBuf2RootNtk, Abc_Lit2Var(iIdLit)) == iRNtk ) - return Abc_LitNotCond( Vec_IntEntry(pNew->vBarBufs, Abc_Lit2Var(iIdLit)), Abc_LitIsCompl(iRes) ^ Abc_LitIsCompl(iIdLit) ); - assert( Bac_ManNtkIsOk(p, iLNtk) && Bac_ManNtkIsOk(p, iRNtk) ); - Vec_IntPush( &p->vBuf2LeafNtk, iLNtk ); - Vec_IntPush( &p->vBuf2LeafObj, iLObj ); - Vec_IntPush( &p->vBuf2RootNtk, iRNtk ); - Vec_IntPush( &p->vBuf2RootObj, iRObj ); - iBufLit = Gia_ManAppendBuf( pNew, iRes ); - if ( vMap ) - { - Vec_IntSetEntryFull( vMap, Abc_Lit2Var(iRes), Abc_Var2Lit(Vec_IntSize(pNew->vBarBufs), Abc_LitIsCompl(iRes)) ); - Vec_IntPush( pNew->vBarBufs, iBufLit ); - } - return iBufLit; -} -int Bac_ManExtract_rec( Gia_Man_t * pNew, Bac_Ntk_t * p, int i, int fBuffers, Vec_Int_t * vMap ) -{ - int iRes = Bac_ObjCopy( p, i ); - if ( iRes >= 0 ) - return iRes; - if ( Bac_ObjIsCo(p, i) ) - iRes = Bac_ManExtract_rec( pNew, p, Bac_ObjFanin(p, i), fBuffers, vMap ); - else if ( Bac_ObjIsPi(p, i) ) - { - Bac_Ntk_t * pHost = Bac_NtkHostNtk( p ); - int iObj = Bac_BoxBi( pHost, Bac_NtkHostObj(p), Bac_ObjIndex(p, i) ); - iRes = Bac_ManExtract_rec( pNew, pHost, iObj, fBuffers, vMap ); - if ( fBuffers ) - iRes = Bac_ManAddBarbuf( pNew, iRes, p->pDesign, Bac_NtkId(p), i, Bac_NtkId(pHost), iObj, vMap ); - } - else if ( Bac_ObjIsBo(p, i) ) - { - int iBox = Bac_BoxBoBox(p, i); - if ( Bac_ObjIsBoxUser(p, iBox) ) // user box - { - Bac_Ntk_t * pBox = Bac_BoxBoNtk( p, i ); - int iObj = Bac_NtkPo( pBox, Bac_ObjIndex(p, i) ); - iRes = Bac_ManExtract_rec( pNew, pBox, iObj, fBuffers, vMap ); - if ( fBuffers ) - iRes = Bac_ManAddBarbuf( pNew, iRes, p->pDesign, Bac_NtkId(p), i, Bac_NtkId(pBox), iObj, vMap ); - } - else // primitive - { - int iFanin, nLits, pLits[16]; - assert( Bac_ObjIsBoxPrim(p, iBox) ); - Bac_BoxForEachFanin( p, iBox, iFanin, nLits ) - pLits[nLits] = Bac_ManExtract_rec( pNew, p, iFanin, fBuffers, vMap ); - assert( nLits <= 16 ); - if ( p->pDesign->ppGraphs ) // mapped gate - { - extern int Gia_ManFactorGraph( Gia_Man_t * p, Dec_Graph_t * pFForm, Vec_Int_t * vLeaves ); - Dec_Graph_t * pGraph = (Dec_Graph_t *)p->pDesign->ppGraphs[Bac_BoxNtkId(p, iBox)]; - Vec_Int_t Leaves = { nLits, nLits, pLits }; - assert( pGraph != NULL ); - return Gia_ManFactorGraph( pNew, pGraph, &Leaves ); - } - else - { - Bac_ObjType_t Type = Bac_ObjType(p, iBox); - if ( nLits == 0 ) - { - if ( Type == BAC_BOX_CF ) - iRes = 0; - else if ( Type == BAC_BOX_CT ) - iRes = 1; - else assert( 0 ); - } - else if ( nLits == 1 ) - { - if ( Type == BAC_BOX_BUF ) - iRes = pLits[0]; - else if ( Type == BAC_BOX_INV ) - iRes = Abc_LitNot( pLits[0] ); - else assert( 0 ); - } - else if ( nLits == 2 ) - { - if ( Type == BAC_BOX_AND ) - iRes = Gia_ManHashAnd( pNew, pLits[0], pLits[1] ); - else if ( Type == BAC_BOX_NAND ) - iRes = Abc_LitNot( Gia_ManHashAnd( pNew, pLits[0], pLits[1] ) ); - else if ( Type == BAC_BOX_OR ) - iRes = Gia_ManHashOr( pNew, pLits[0], pLits[1] ); - else if ( Type == BAC_BOX_NOR ) - iRes = Abc_LitNot( Gia_ManHashOr( pNew, pLits[0], pLits[1] ) ); - else if ( Type == BAC_BOX_XOR ) - iRes = Gia_ManHashXor( pNew, pLits[0], pLits[1] ); - else if ( Type == BAC_BOX_XNOR ) - iRes = Abc_LitNot( Gia_ManHashXor( pNew, pLits[0], pLits[1] ) ); - else if ( Type == BAC_BOX_SHARP ) - iRes = Gia_ManHashAnd( pNew, pLits[0], Abc_LitNot(pLits[1]) ); - else if ( Type == BAC_BOX_SHARPL ) - iRes = Gia_ManHashAnd( pNew, Abc_LitNot(pLits[0]), pLits[1] ); - else assert( 0 ); - } - else if ( nLits == 3 ) - { - if ( Type == BAC_BOX_MUX ) - iRes = Gia_ManHashMux( pNew, pLits[0], pLits[1], pLits[2] ); - else if ( Type == BAC_BOX_MAJ ) - iRes = Gia_ManHashMaj( pNew, pLits[0], pLits[1], pLits[2] ); - else if ( Type == BAC_BOX_ADD ) - { - int iRes0 = Gia_ManHashAnd( pNew, pLits[1], pLits[2] ); - int iRes1 = Gia_ManHashOr( pNew, pLits[1], pLits[2] ); - assert( Bac_BoxBoNum(p, iBox) == 2 ); - if ( Bac_BoxBo(p, iBox, 0) == i ) // sum - iRes = Gia_ManHashXor( pNew, pLits[0], Gia_ManHashAnd(pNew, Abc_LitNot(iRes0), iRes1) ); - else if ( Bac_BoxBo(p, iBox, 1) == i ) // cout - iRes = Gia_ManHashOr( pNew, iRes0, Gia_ManHashAnd(pNew, pLits[0], iRes1) ); - else assert( 0 ); - } - else assert( 0 ); - } - else assert( 0 ); - } - } - } - else assert( 0 ); - Bac_ObjSetCopy( p, i, iRes ); - return iRes; -} -Gia_Man_t * Bac_ManExtract( Bac_Man_t * p, int fBuffers, int fVerbose ) -{ - Bac_Ntk_t * pNtk, * pRoot = Bac_ManRoot(p); - Gia_Man_t * pNew, * pTemp; - Vec_Int_t * vMap = NULL; - int i, iObj; - - Vec_IntClear( &p->vBuf2LeafNtk ); - Vec_IntClear( &p->vBuf2LeafObj ); - Vec_IntClear( &p->vBuf2RootNtk ); - Vec_IntClear( &p->vBuf2RootObj ); - - Bac_ManForEachNtk( p, pNtk, i ) - { - Bac_NtkDeriveIndex( pNtk ); - Bac_NtkStartCopies( pNtk ); - } - - // start the manager - pNew = Gia_ManStart( Bac_ManNodeNum(p) ); - pNew->pName = Abc_UtilStrsav(p->pName); - pNew->pSpec = Abc_UtilStrsav(p->pSpec); - - // primary inputs - Bac_NtkForEachPi( pRoot, iObj, i ) - Bac_ObjSetCopy( pRoot, iObj, Gia_ManAppendCi(pNew) ); - - // internal nodes - Gia_ManHashAlloc( pNew ); - pNew->vBarBufs = Vec_IntAlloc( 10000 ); - vMap = Vec_IntStartFull( 10000 ); - Bac_ManPrepareGates( p ); - Bac_NtkForEachPo( pRoot, iObj, i ) - Bac_ManExtract_rec( pNew, pRoot, iObj, fBuffers, vMap ); - Bac_ManUndoGates( p ); - Vec_IntFreeP( &vMap ); - Gia_ManHashStop( pNew ); - - // primary outputs - Bac_NtkForEachPo( pRoot, iObj, i ) - Gia_ManAppendCo( pNew, Bac_ObjCopy(pRoot, iObj) ); - assert( Vec_IntSize(&p->vBuf2LeafNtk) == pNew->nBufs ); - - // cleanup - pNew = Gia_ManCleanup( pTemp = pNew ); - Gia_ManStop( pTemp ); - //Gia_ManPrintStats( pNew, NULL ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Mark each GIA node with the network it belongs to.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_ManMarkNodesGia( Bac_Man_t * p, Gia_Man_t * pGia ) -{ - Gia_Obj_t * pObj; int i, Count = 0; - assert( Vec_IntSize(&p->vBuf2LeafNtk) == Gia_ManBufNum(pGia) ); - Gia_ManConst0(pGia)->Value = 1; - Gia_ManForEachPi( pGia, pObj, i ) - pObj->Value = 1; - Gia_ManForEachAnd( pGia, pObj, i ) - { - if ( Gia_ObjIsBuf(pObj) ) - pObj->Value = Vec_IntEntry( &p->vBuf2LeafNtk, Count++ ); - else - { - pObj->Value = Gia_ObjFanin0(pObj)->Value; - assert( pObj->Value == Gia_ObjFanin1(pObj)->Value ); - } - } - assert( Count == Gia_ManBufNum(pGia) ); - Gia_ManForEachPo( pGia, pObj, i ) - { - assert( Gia_ObjFanin0(pObj)->Value == 1 ); - pObj->Value = 1; - } -} -void Bac_ManRemapBarbufs( Bac_Man_t * pNew, Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int Entry, i; - //assert( Vec_IntSize(&p->vBuf2RootNtk) ); - assert( !Vec_IntSize(&pNew->vBuf2RootNtk) ); - Vec_IntAppend( &pNew->vBuf2RootNtk, &p->vBuf2RootNtk ); - Vec_IntAppend( &pNew->vBuf2RootObj, &p->vBuf2RootObj ); - Vec_IntAppend( &pNew->vBuf2LeafNtk, &p->vBuf2LeafNtk ); - Vec_IntAppend( &pNew->vBuf2LeafObj, &p->vBuf2LeafObj ); - Vec_IntForEachEntry( &p->vBuf2LeafObj, Entry, i ) - { - pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2LeafNtk, i) ); - Vec_IntWriteEntry( &pNew->vBuf2LeafObj, i, Bac_ObjCopy(pNtk, Entry) ); - } - Vec_IntForEachEntry( &p->vBuf2RootObj, Entry, i ) - { - pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, i) ); - Vec_IntWriteEntry( &pNew->vBuf2RootObj, i, Bac_ObjCopy(pNtk, Entry) ); - } -} -void Bac_NtkCreateAndConnectBuffer( Gia_Man_t * pGia, Gia_Obj_t * pObj, Bac_Ntk_t * p, int iTerm ) -{ - int iObj; - if ( pGia && Gia_ObjFaninId0p(pGia, pObj) > 0 ) - { - iObj = Bac_ObjAlloc( p, BAC_OBJ_BI, Gia_ObjFanin0(pObj)->Value ); - Bac_ObjAlloc( p, Gia_ObjFaninC0(pObj) ? BAC_BOX_INV : BAC_BOX_BUF, -1 ); - } - else - { - Bac_ObjAlloc( p, pGia && Gia_ObjFaninC0(pObj) ? BAC_BOX_CT : BAC_BOX_CF, -1 ); - } - iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 ); - Bac_ObjSetFanin( p, iTerm, iObj ); -} -void Bac_NtkInsertGia( Bac_Man_t * p, Gia_Man_t * pGia ) -{ - Bac_Ntk_t * pNtk, * pRoot = Bac_ManRoot( p ); - int i, j, k, iBox, iTerm, Count = 0; - Gia_Obj_t * pObj; - - Gia_ManConst0(pGia)->Value = ~0; - Gia_ManForEachPi( pGia, pObj, i ) - pObj->Value = Bac_NtkPi( pRoot, i ); - Gia_ManForEachAnd( pGia, pObj, i ) - { - if ( Gia_ObjIsBuf(pObj) ) - { - pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, Count) ); - iTerm = Vec_IntEntry( &p->vBuf2RootObj, Count ); - assert( Bac_ObjIsCo(pNtk, iTerm) ); - if ( Bac_ObjFanin(pNtk, iTerm) == -1 ) // not a feedthrough - Bac_NtkCreateAndConnectBuffer( pGia, pObj, pNtk, iTerm ); - // prepare leaf - pObj->Value = Vec_IntEntry( &p->vBuf2LeafObj, Count++ ); - } - else - { - int iLit0 = Gia_ObjFanin0(pObj)->Value; - int iLit1 = Gia_ObjFanin1(pObj)->Value; - Bac_ObjType_t Type; - pNtk = Bac_ManNtk( p, pObj->Value ); - if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) ) - Type = BAC_BOX_NOR; - else if ( Gia_ObjFaninC1(pObj) ) - Type = BAC_BOX_SHARP; - else if ( Gia_ObjFaninC0(pObj) ) - { - Type = BAC_BOX_SHARP; - ABC_SWAP( int, iLit0, iLit1 ); - } - else - Type = BAC_BOX_AND; - // create box - iTerm = Bac_ObjAlloc( pNtk, BAC_OBJ_BI, iLit1 ); - iTerm = Bac_ObjAlloc( pNtk, BAC_OBJ_BI, iLit0 ); - Bac_ObjAlloc( pNtk, Type, -1 ); - pObj->Value = Bac_ObjAlloc( pNtk, BAC_OBJ_BO, -1 ); - } - } - assert( Count == Gia_ManBufNum(pGia) ); - - // create constant 0 drivers for COs without barbufs - Bac_ManForEachNtk( p, pNtk, i ) - { - Bac_NtkForEachBox( pNtk, iBox ) - Bac_BoxForEachBi( pNtk, iBox, iTerm, j ) - if ( Bac_ObjFanin(pNtk, iTerm) == -1 ) - Bac_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm ); - Bac_NtkForEachPo( pNtk, iTerm, k ) - if ( pNtk != pRoot && Bac_ObjFanin(pNtk, iTerm) == -1 ) - Bac_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm ); - } - // create node and connect POs - Gia_ManForEachPo( pGia, pObj, i ) - if ( Bac_ObjFanin(pRoot, Bac_NtkPo(pRoot, i)) == -1 ) // not a feedthrough - Bac_NtkCreateAndConnectBuffer( pGia, pObj, pRoot, Bac_NtkPo(pRoot, i) ); -} -Bac_Man_t * Bac_ManInsertGia( Bac_Man_t * p, Gia_Man_t * pGia ) -{ - Bac_Man_t * pNew = Bac_ManDupUserBoxes( p ); - Bac_ManMarkNodesGia( p, pGia ); - Bac_ManRemapBarbufs( pNew, p ); - Bac_NtkInsertGia( pNew, pGia ); - Bac_ManMoveNames( pNew, p ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Bac_Man_t * Bac_ManBlastTest( Bac_Man_t * p ) -{ - Gia_Man_t * pGia = Bac_ManExtract( p, 1, 0 ); - Bac_Man_t * pNew = Bac_ManInsertGia( p, pGia ); - Gia_ManStop( pGia ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Mark each GIA node with the network it belongs to.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Abc_NodeIsSeriousGate( Abc_Obj_t * p ) -{ - return Abc_ObjIsNode(p) && Abc_ObjFaninNum(p) > 0 && !Abc_ObjIsBarBuf(p); -} -void Bac_ManMarkNodesAbc( Bac_Man_t * p, Abc_Ntk_t * pNtk ) -{ - Abc_Obj_t * pObj, * pFanin; int i, k, Count = 0; - assert( Vec_IntSize(&p->vBuf2LeafNtk) == pNtk->nBarBufs2 ); - Abc_NtkForEachPi( pNtk, pObj, i ) - pObj->iTemp = 1; - Abc_NtkForEachNode( pNtk, pObj, i ) - { - if ( Abc_ObjIsBarBuf(pObj) ) - pObj->iTemp = Vec_IntEntry( &p->vBuf2LeafNtk, Count++ ); - else if ( Abc_NodeIsSeriousGate(pObj) ) - { - pObj->iTemp = Abc_ObjFanin0(pObj)->iTemp; - Abc_ObjForEachFanin( pObj, pFanin, k ) - assert( pObj->iTemp == pFanin->iTemp ); - } - } - Abc_NtkForEachPo( pNtk, pObj, i ) - { - if ( !Abc_NodeIsSeriousGate(Abc_ObjFanin0(pObj)) ) - continue; - assert( Abc_ObjFanin0(pObj)->iTemp == 1 ); - pObj->iTemp = Abc_ObjFanin0(pObj)->iTemp; - } - assert( Count == pNtk->nBarBufs2 ); -} -void Bac_NtkCreateOrConnectFanin( Abc_Obj_t * pFanin, Bac_Ntk_t * p, int iTerm ) -{ - int iObj; - if ( pFanin && Abc_NodeIsSeriousGate(pFanin) )//&& Bac_ObjName(p, pFanin->iTemp) == -1 ) // gate without name - { - iObj = pFanin->iTemp; - } - else if ( pFanin && (Abc_ObjIsPi(pFanin) || Abc_ObjIsBarBuf(pFanin) || Abc_NodeIsSeriousGate(pFanin)) ) // PI/BO or gate with name - { - iObj = Bac_ObjAlloc( p, BAC_OBJ_BI, pFanin->iTemp ); - Bac_ObjAlloc( p, BAC_BOX_GATE, p->pDesign->ElemGates[2] ); // buffer - iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 ); - } - else - { - assert( !pFanin || Abc_NodeIsConst0(pFanin) || Abc_NodeIsConst1(pFanin) ); - Bac_ObjAlloc( p, BAC_BOX_GATE, p->pDesign->ElemGates[(pFanin && Abc_NodeIsConst1(pFanin))] ); // const 0/1 - iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 ); - } - Bac_ObjSetFanin( p, iTerm, iObj ); -} -void Bac_NtkPrepareLibrary( Bac_Man_t * p, Mio_Library_t * pLib ) -{ - Mio_Gate_t * pGate; - Mio_Gate_t * pGate0 = Mio_LibraryReadConst0( pLib ); - Mio_Gate_t * pGate1 = Mio_LibraryReadConst1( pLib ); - Mio_Gate_t * pGate2 = Mio_LibraryReadBuf( pLib ); - if ( !pGate0 || !pGate1 || !pGate2 ) - { - printf( "The library does not have one of the elementary gates.\n" ); - return; - } - p->ElemGates[0] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate0), NULL ); - p->ElemGates[1] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate1), NULL ); - p->ElemGates[2] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate2), NULL ); - Mio_LibraryForEachGate( pLib, pGate ) - if ( pGate != pGate0 && pGate != pGate1 && pGate != pGate2 ) - Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate), NULL ); - assert( Abc_NamObjNumMax(p->pMods) > 1 ); -} -int Bac_NtkBuildLibrary( Bac_Man_t * p ) -{ - int RetValue = 1; - Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - if ( pLib == NULL ) - printf( "The standard cell library is not available.\n" ), RetValue = 0; - else - Bac_NtkPrepareLibrary( p, pLib ); - p->pMioLib = pLib; - return RetValue; -} -void Bac_NtkInsertNtk( Bac_Man_t * p, Abc_Ntk_t * pNtk ) -{ - Bac_Ntk_t * pCbaNtk, * pRoot = Bac_ManRoot( p ); - int i, j, k, iBox, iTerm, Count = 0; - Abc_Obj_t * pObj; - assert( Abc_NtkHasMapping(pNtk) ); - Bac_NtkPrepareLibrary( p, (Mio_Library_t *)pNtk->pManFunc ); - p->pMioLib = pNtk->pManFunc; - - Abc_NtkForEachPi( pNtk, pObj, i ) - pObj->iTemp = Bac_NtkPi( pRoot, i ); - Abc_NtkForEachNode( pNtk, pObj, i ) - { - if ( Abc_ObjIsBarBuf(pObj) ) - { - pCbaNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, Count) ); - iTerm = Vec_IntEntry( &p->vBuf2RootObj, Count ); - assert( Bac_ObjIsCo(pCbaNtk, iTerm) ); - if ( Bac_ObjFanin(pCbaNtk, iTerm) == -1 ) // not a feedthrough - Bac_NtkCreateOrConnectFanin( Abc_ObjFanin0(pObj), pCbaNtk, iTerm ); - // prepare leaf - pObj->iTemp = Vec_IntEntry( &p->vBuf2LeafObj, Count++ ); - } - else if ( Abc_NodeIsSeriousGate(pObj) ) - { - pCbaNtk = Bac_ManNtk( p, pObj->iTemp ); - for ( k = Abc_ObjFaninNum(pObj)-1; k >= 0; k-- ) - iTerm = Bac_ObjAlloc( pCbaNtk, BAC_OBJ_BI, Abc_ObjFanin(pObj, k)->iTemp ); - Bac_ObjAlloc( pCbaNtk, BAC_BOX_GATE, Abc_NamStrFind(p->pMods, Mio_GateReadName((Mio_Gate_t *)pObj->pData)) ); - pObj->iTemp = Bac_ObjAlloc( pCbaNtk, BAC_OBJ_BO, -1 ); - } - } - assert( Count == pNtk->nBarBufs2 ); - - // create constant 0 drivers for COs without barbufs - Bac_ManForEachNtk( p, pCbaNtk, i ) - { - Bac_NtkForEachBox( pCbaNtk, iBox ) - Bac_BoxForEachBi( pCbaNtk, iBox, iTerm, j ) - if ( Bac_ObjFanin(pCbaNtk, iTerm) == -1 ) - Bac_NtkCreateOrConnectFanin( NULL, pCbaNtk, iTerm ); - Bac_NtkForEachPo( pCbaNtk, iTerm, k ) - if ( pCbaNtk != pRoot && Bac_ObjFanin(pCbaNtk, iTerm) == -1 ) - Bac_NtkCreateOrConnectFanin( NULL, pCbaNtk, iTerm ); - } - // create node and connect POs - Abc_NtkForEachPo( pNtk, pObj, i ) - if ( Bac_ObjFanin(pRoot, Bac_NtkPo(pRoot, i)) == -1 ) // not a feedthrough - Bac_NtkCreateOrConnectFanin( Abc_ObjFanin0(pObj), pRoot, Bac_NtkPo(pRoot, i) ); -} -void * Bac_ManInsertAbc( Bac_Man_t * p, void * pAbc ) -{ - Abc_Ntk_t * pNtk = (Abc_Ntk_t *)pAbc; - Bac_Man_t * pNew = Bac_ManDupUserBoxes( p ); - Bac_ManMarkNodesAbc( p, pNtk ); - Bac_ManRemapBarbufs( pNew, p ); - Bac_NtkInsertNtk( pNew, pNtk ); - Bac_ManMoveNames( pNew, p ); - return pNew; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacCom.c b/src/base/bac/bacCom.c deleted file mode 100644 index f1e3be5fa..000000000 --- a/src/base/bac/bacCom.c +++ /dev/null @@ -1,728 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacCom.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Command handlers.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacCom.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" -#include "proof/cec/cec.h" -#include "base/main/mainInt.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -static int Bac_CommandRead ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandWrite ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandPs ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandPut ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandGet ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandClp ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandCec ( Abc_Frame_t * pAbc, int argc, char ** argv ); -static int Bac_CommandTest ( Abc_Frame_t * pAbc, int argc, char ** argv ); - -static inline Bac_Man_t * Bac_AbcGetMan( Abc_Frame_t * pAbc ) { return (Bac_Man_t *)pAbc->pAbcBac; } -static inline void Bac_AbcFreeMan( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcBac ) Bac_ManFree(Bac_AbcGetMan(pAbc)); } -static inline void Bac_AbcUpdateMan( Abc_Frame_t * pAbc, Bac_Man_t * p ) { Bac_AbcFreeMan(pAbc); pAbc->pAbcBac = p; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function******************************************************************** - - Synopsis [Accessing current Bac_Ntk_t.] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Abc_FrameImportPtr( Vec_Ptr_t * vPtr ) -{ - Bac_Man_t * p; - if ( Abc_FrameGetGlobalFrame() == NULL ) - { - printf( "ABC framework is not started.\n" ); - return; - } - p = Bac_PtrTransformToCba( vPtr ); - if ( p == NULL ) - printf( "Converting from Ptr failed.\n" ); - Bac_AbcUpdateMan( Abc_FrameGetGlobalFrame(), p ); -} -Vec_Ptr_t * Abc_FrameExportPtr() -{ - Vec_Ptr_t * vPtr; - Bac_Man_t * p; - if ( Abc_FrameGetGlobalFrame() == NULL ) - { - printf( "ABC framework is not started.\n" ); - return NULL; - } - p = Bac_AbcGetMan( Abc_FrameGetGlobalFrame() ); - if ( p == NULL ) - printf( "There is no CBA design present.\n" ); - vPtr = Bac_PtrDeriveFromCba( p ); - if ( vPtr == NULL ) - printf( "Converting to Ptr has failed.\n" ); - return vPtr; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Bac_Init( Abc_Frame_t * pAbc ) -{ - Cmd_CommandAdd( pAbc, "New word level", "@_read", Bac_CommandRead, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_write", Bac_CommandWrite, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_ps", Bac_CommandPs, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_put", Bac_CommandPut, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_get", Bac_CommandGet, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_clp", Bac_CommandClp, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_cec", Bac_CommandCec, 0 ); - Cmd_CommandAdd( pAbc, "New word level", "@_test", Bac_CommandTest, 0 ); -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Bac_End( Abc_Frame_t * pAbc ) -{ - Bac_AbcFreeMan( pAbc ); -} - - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - FILE * pFile; - Bac_Man_t * p = NULL; - Vec_Ptr_t * vDes = NULL; - char * pFileName = NULL; - int c, fUseAbc = 0, fUsePtr = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "apvh" ) ) != EOF ) - { - switch ( c ) - { - case 'a': - fUseAbc ^= 1; - break; - case 'p': - fUsePtr ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( argc != globalUtilOptind + 1 ) - { - printf( "Bac_CommandRead(): Input file name should be given on the command line.\n" ); - return 0; - } - // get the file name - pFileName = argv[globalUtilOptind]; - if ( (pFile = fopen( pFileName, "r" )) == NULL ) - { - Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName ); - if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".blif", ".smt", ".bac", NULL )) ) - Abc_Print( 1, "Did you mean \"%s\"?", pFileName ); - Abc_Print( 1, "\n" ); - return 0; - } - fclose( pFile ); - // perform reading - if ( fUseAbc || fUsePtr ) - { - extern Vec_Ptr_t * Ptr_AbcDeriveDes( Abc_Ntk_t * pNtk ); - Abc_Ntk_t * pAbcNtk = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), 0 ); - Vec_Ptr_t * vDes = Ptr_AbcDeriveDes( pAbcNtk ); - p = Bac_PtrTransformToCba( vDes ); - Bac_PtrFree( vDes ); // points to names in pAbcNtk - if ( p ) - { - ABC_FREE( p->pSpec ); - p->pSpec = Abc_UtilStrsav( pAbcNtk->pSpec ); - } - Abc_NtkDelete( pAbcNtk ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - { - vDes = Psr_ManReadBlif( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Psr_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Psr_ManVecFree( vDes ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - { - vDes = Psr_ManReadVerilog( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Psr_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Psr_ManVecFree( vDes ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "smt" ) ) - { - vDes = NULL;//Psr_ManReadSmt( pFileName ); - if ( vDes && Vec_PtrSize(vDes) ) - p = Psr_ManBuildCba( pFileName, vDes ); - if ( vDes ) - Psr_ManVecFree( vDes ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "bac" ) ) - { - p = Bac_ManReadBac( pFileName ); - } - else - { - printf( "Unrecognized input file extension.\n" ); - return 0; - } - Bac_AbcUpdateMan( pAbc, p ); - return 0; -usage: - Abc_Print( -2, "usage: @_read [-apvh] \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-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * p = Bac_AbcGetMan(pAbc); - char * pFileName = NULL; - int fUseAssign = 1; - int fUsePtr = 0; - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "apvh" ) ) != EOF ) - { - switch ( c ) - { - case 'a': - fUseAssign ^= 1; - break; - case 'p': - fUsePtr ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandWrite(): There is no current design.\n" ); - return 0; - } - if ( argc == globalUtilOptind + 1 ) - pFileName = argv[globalUtilOptind]; - else if ( argc == globalUtilOptind && p ) - pFileName = Extra_FileNameGenericAppend( Bac_ManName(p), "_out.v" ); - else - { - printf( "Output file name should be given on the command line.\n" ); - return 0; - } - // perform writing - if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - Bac_ManWriteBlif( pFileName, p ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - { - if ( fUsePtr ) - { - Vec_Ptr_t * vPtr = Bac_PtrDeriveFromCba( p ); - if ( vPtr == NULL ) - printf( "Converting to Ptr has failed.\n" ); - else - { - Bac_PtrDumpVerilog( pFileName, vPtr ); - Bac_PtrFree( vPtr ); - } - } - else - Bac_ManWriteVerilog( pFileName, p, fUseAssign ); - } - else if ( !strcmp( Extra_FileNameExtension(pFileName), "bac" ) ) - Bac_ManWriteBac( pFileName, p ); - else - { - printf( "Unrecognized output file extension.\n" ); - return 0; - } - return 0; -usage: - Abc_Print( -2, "usage: @_write [-apvh]\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-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * p = Bac_AbcGetMan(pAbc); - int c, nModules = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "Mvh" ) ) != EOF ) - { - switch ( c ) - { - case 'M': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" ); - goto usage; - } - nModules = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( nModules < 0 ) - goto usage; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandPs(): There is no current design.\n" ); - return 0; - } - Bac_ManPrintStats( p, nModules, fVerbose ); - return 0; -usage: - Abc_Print( -2, "usage: @_ps [-M num] [-vh]\n" ); - Abc_Print( -2, "\t prints statistics\n" ); - Abc_Print( -2, "\t-M num : the number of first modules to report [default = %d]\n", nModules ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandPut( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * p = Bac_AbcGetMan(pAbc); - Gia_Man_t * pGia = NULL; - int c, fBarBufs = 1, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "bvh" ) ) != EOF ) - { - switch ( c ) - { - case 'b': - fBarBufs ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandPut(): There is no current design.\n" ); - return 0; - } - pGia = Bac_ManExtract( p, fBarBufs, fVerbose ); - if ( pGia == NULL ) - { - Abc_Print( 1, "Bac_CommandPut(): Conversion to AIG has failed.\n" ); - return 0; - } - Abc_FrameUpdateGia( pAbc, pGia ); - return 0; -usage: - Abc_Print( -2, "usage: @_put [-bvh]\n" ); - Abc_Print( -2, "\t extracts AIG from the hierarchical design\n" ); - Abc_Print( -2, "\t-b : toggle using barrier buffers [default = %s]\n", fBarBufs? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandGet( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * pNew = NULL, * p = Bac_AbcGetMan(pAbc); - int c, fMapped = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF ) - { - switch ( c ) - { - case 'm': - fMapped ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandGet(): There is no current design.\n" ); - return 0; - } - if ( fMapped ) - { - if ( pAbc->pNtkCur == NULL ) - { - Abc_Print( 1, "Bac_CommandGet(): There is no current mapped design.\n" ); - return 0; - } - pNew = (Bac_Man_t *)Bac_ManInsertAbc( p, pAbc->pNtkCur ); - } - else - { - if ( pAbc->pGia == NULL ) - { - Abc_Print( 1, "Bac_CommandGet(): There is no current AIG.\n" ); - return 0; - } - pNew = Bac_ManInsertGia( p, pAbc->pGia ); - } - Bac_AbcUpdateMan( pAbc, pNew ); - return 0; -usage: - Abc_Print( -2, "usage: @_get [-mvh]\n" ); - Abc_Print( -2, "\t inserts AIG or mapped network into the hierarchical design\n" ); - Abc_Print( -2, "\t-m : toggle using mapped network from main-space [default = %s]\n", fMapped? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandClp( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * pNew = NULL, * p = Bac_AbcGetMan(pAbc); - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandGet(): There is no current design.\n" ); - return 0; - } - pNew = Bac_ManCollapse( p ); - Bac_AbcUpdateMan( pAbc, pNew ); - return 0; -usage: - Abc_Print( -2, "usage: @_clp [-vh]\n" ); - Abc_Print( -2, "\t collapses the current hierarchical design\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Bac_Man_t * p = Bac_AbcGetMan(pAbc); - Gia_Man_t * pFirst, * pSecond, * pMiter; - Cec_ParCec_t ParsCec, * pPars = &ParsCec; - Vec_Ptr_t * vDes; - char * FileName, * pStr, ** pArgvNew; - int c, nArgcNew, fDumpMiter = 0; - FILE * pFile; - Cec_ManCecSetDefaultParams( pPars ); - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - pPars->fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandCec(): There is no current design.\n" ); - return 0; - } - pArgvNew = argv + globalUtilOptind; - nArgcNew = argc - globalUtilOptind; - if ( nArgcNew != 1 ) - { - if ( p->pSpec == NULL ) - { - Abc_Print( -1, "File name is not given on the command line.\n" ); - return 1; - } - FileName = p->pSpec; - } - else - FileName = pArgvNew[0]; - // fix the wrong symbol - for ( pStr = FileName; *pStr; pStr++ ) - if ( *pStr == '>' ) - *pStr = '\\'; - if ( (pFile = fopen( FileName, "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, "\n" ); - return 1; - } - fclose( pFile ); - - // extract AIG from the current design - pFirst = Bac_ManExtract( 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 = Psr_ManReadBlif( FileName ); - else if ( !strcmp( Extra_FileNameExtension(FileName), "v" ) ) - vDes = Psr_ManReadVerilog( FileName ); - else assert( 0 ); - p = Psr_ManBuildCba( FileName, vDes ); - Psr_ManVecFree( vDes ); - pSecond = Bac_ManExtract( p, 0, 0 ); - Bac_ManFree( p ); - if ( pSecond == NULL ) - { - Gia_ManStop( pFirst ); - Abc_Print( -1, "Extracting AIG from the original design has failed.\n" ); - return 0; - } - // compute the miter - pMiter = Gia_ManMiter( pFirst, pSecond, 0, 1, 0, 0, pPars->fVerbose ); - if ( pMiter ) - { - if ( fDumpMiter ) - { - Abc_Print( 0, "The verification miter is written into file \"%s\".\n", "cec_miter.aig" ); - Gia_AigerWrite( pMiter, "cec_miter.aig", 0, 0, 0 ); - } - pAbc->Status = Cec_ManVerify( pMiter, pPars ); - //Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb ); - Gia_ManStop( pMiter ); - } - Gia_ManStop( pFirst ); - Gia_ManStop( pSecond ); - return 0; -usage: - Abc_Print( -2, "usage: @_cec [-vh]\n" ); - Abc_Print( -2, "\t combinational equivalence checking\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Bac_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - extern void Psr_ManReadBlifTest(); - extern void Psr_ManReadVerilogTest(); - extern void Psr_SmtReadSmtTest(); - //Bac_Man_t * p = Bac_AbcGetMan(pAbc); - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } -/* - if ( p == NULL ) - { - Abc_Print( 1, "Bac_CommandTest(): There is no current design.\n" ); - return 0; - } -*/ - //Bac_PtrTransformTestTest(); - //Psr_ManReadVerilogTest(); - //Psr_SmtReadSmtTest(); - return 0; -usage: - Abc_Print( -2, "usage: @_test [-vh]\n" ); - Abc_Print( -2, "\t experiments with word-level networks\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacLib.c b/src/base/bac/bacLib.c deleted file mode 100644 index b2a16eb6c..000000000 --- a/src/base/bac/bacLib.c +++ /dev/null @@ -1,52 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacLib.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Library procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacLib.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacNtk.c b/src/base/bac/bacNtk.c deleted file mode 100644 index cd08b0b6d..000000000 --- a/src/base/bac/bacNtk.c +++ /dev/null @@ -1,603 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacNtk.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Netlist manipulation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacNtk.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Bac_Pair_t_ Bac_Pair_t; -struct Bac_Pair_t_ -{ - Bac_ObjType_t Type; - char * pName; - char * pSymb; -}; -static const char * s_Pref = "ABC_"; -static Bac_Pair_t s_Types[BAC_BOX_UNKNOWN] = -{ - { BAC_OBJ_NONE, "NONE", NULL }, - { BAC_OBJ_PI, "PI", NULL }, - { BAC_OBJ_PO, "PO", NULL }, - { BAC_OBJ_BI, "BI", NULL }, - { BAC_OBJ_BO, "BO", NULL }, - { BAC_OBJ_BOX, "BOX", NULL }, - - { BAC_BOX_CF, "CF", "o" }, - { BAC_BOX_CT, "CT", "o" }, - { BAC_BOX_CX, "CX", "o" }, - { BAC_BOX_CZ, "CZ", "o" }, - { BAC_BOX_BUF, "BUF", "ao" }, - { BAC_BOX_INV, "INV", "ao" }, - { BAC_BOX_AND, "AND", "abo" }, - { BAC_BOX_NAND, "NAND", "abo" }, - { BAC_BOX_OR, "OR", "abo" }, - { BAC_BOX_NOR, "NOR", "abo" }, - { BAC_BOX_XOR, "XOR", "abo" }, - { BAC_BOX_XNOR, "XNOR", "abo" }, - { BAC_BOX_SHARP, "SHARP", "abo" }, - { BAC_BOX_SHARPL, "SHARPL", "abo" }, - { BAC_BOX_MUX, "MUX", "cabo" }, - { BAC_BOX_MAJ, "MAJ", "abco" }, - - { BAC_BOX_RAND, "RAND", "ao" }, - { BAC_BOX_RNAND, "RNAND", "ao" }, - { BAC_BOX_ROR, "ROR", "ao" }, - { BAC_BOX_RNOR, "RNOR", "ao" }, - { BAC_BOX_RXOR, "RXOR", "ao" }, - { BAC_BOX_RXNOR, "RXNOR", "ao" }, - - { BAC_BOX_LAND, "LAND", "abo" }, - { BAC_BOX_LNAND, "LNAND", "abo" }, - { BAC_BOX_LOR, "LOR", "abo" }, - { BAC_BOX_LNOR, "LNOR", "abo" }, - { BAC_BOX_LXOR, "LXOR", "abo" }, - { BAC_BOX_LXNOR, "LXNOR", "abo" }, - - { BAC_BOX_NMUX, "NMUX", "abo" }, - { BAC_BOX_SEL, "SEL", "abo" }, - { BAC_BOX_PSEL, "PSEL", "iabo" }, - { BAC_BOX_ENC, "ENC", "ao" }, - { BAC_BOX_PENC, "PENC", "ao" }, - { BAC_BOX_DEC, "DEC", "ao" }, - { BAC_BOX_EDEC, "EDEC", "abo" }, - - { BAC_BOX_ADD, "ADD", "iabso" }, - { BAC_BOX_SUB, "SUB", "abo" }, - { BAC_BOX_MUL, "MUL", "abo" }, - { BAC_BOX_DIV, "DIV", "abo" }, - { BAC_BOX_MOD, "MOD", "abo" }, - { BAC_BOX_REM, "REM", "abo" }, - { BAC_BOX_POW, "POW", "abo" }, - { BAC_BOX_MIN, "MIN", "ao" }, - { BAC_BOX_ABS, "ABS", "ao" }, - - { BAC_BOX_LTHAN, "LTHAN", "iabo" }, - { BAC_BOX_LETHAN, "LETHAN", "abo" }, - { BAC_BOX_METHAN, "METHAN", "abo" }, - { BAC_BOX_MTHAN, "MTHAN", "abo" }, - { BAC_BOX_EQU, "EQU", "abo" }, - { BAC_BOX_NEQU, "NEQU", "abo" }, - - { BAC_BOX_SHIL, "SHIL", "abo" }, - { BAC_BOX_SHIR, "SHIR", "abo" }, - { BAC_BOX_ROTL, "ROTL", "abo" }, - { BAC_BOX_ROTR, "ROTR", "abo" }, - - { BAC_BOX_GATE, "GATE", "io" }, - { BAC_BOX_LUT, "LUT", "io" }, - { BAC_BOX_ASSIGN, "ASSIGN", "abo" }, - - { BAC_BOX_TRI, "TRI", "abo" }, - { BAC_BOX_RAM, "RAM", "eadro" }, - { BAC_BOX_RAMR, "RAMR", "eamo" }, - { BAC_BOX_RAMW, "RAMW", "eado" }, - { BAC_BOX_RAMWC, "RAMWC", "ceado" }, - { BAC_BOX_RAMBOX, "RAMBOX", "io" }, - - { BAC_BOX_LATCH, "LATCH", "dvsgq" }, - { BAC_BOX_LATCHRS, "LATCHRS", "dsrgq" }, - { BAC_BOX_DFF, "DFF", "dvscq" }, - { BAC_BOX_DFFRS, "DFFRS", "dsrcq" } -}; -static inline int Bac_GetTypeId( Bac_ObjType_t Type ) -{ - int i; - for ( i = 1; i < BAC_BOX_UNKNOWN; i++ ) - if ( s_Types[i].Type == Type ) - return i; - return -1; -} -void Bac_ManSetupTypes( char ** pNames, char ** pSymbs ) -{ - int Type; - for ( Type = 1; Type < BAC_BOX_UNKNOWN; Type++ ) - { - int Id = Bac_GetTypeId( (Bac_ObjType_t)Type ); - pNames[Type] = s_Types[Id].pName; - pSymbs[Type] = s_Types[Id].pSymb; - } -} - -char * Bac_NtkGenerateName( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vBits ) -{ - static char Buffer[100]; - char * pTemp; int i, Bits; - char * pName = Bac_ManPrimName( p->pDesign, Type ); - char * pSymb = Bac_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; -} - -Bac_ObjType_t Bac_NameToType( char * pName ) -{ - int i; - if ( strncmp(pName, s_Pref, strlen(s_Pref)) ) - return BAC_OBJ_NONE; - pName += strlen(s_Pref); - for ( i = 1; i < BAC_BOX_UNKNOWN; i++ ) - if ( !strncmp(pName, s_Types[i].pName, strlen(s_Types[i].pName)) ) - return s_Types[i].Type; - return BAC_OBJ_NONE; -} -Vec_Int_t * Bac_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 && !Bac_CharIsDigit(*pTemp); pTemp++ ); - assert( Bac_CharIsDigit(*pTemp) ); - for ( ; *pTemp; pTemp++ ) - { - if ( Bac_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 /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Replaces fanin iOld by iNew in all fanouts.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_NtkUpdateFanout( Bac_Ntk_t * p, int iOld, int iNew ) -{ - int iCo; - assert( Bac_ObjIsCi(p, iOld) ); - assert( Bac_ObjIsCi(p, iNew) ); - Bac_ObjForEachFanout( p, iOld, iCo ) - { - assert( Bac_ObjFanin(p, iCo) == iOld ); - Bac_ObjCleanFanin( p, iCo ); - Bac_ObjSetFanin( p, iCo, iNew ); - } - Bac_ObjSetFanout( p, iNew, Bac_ObjFanout(p, iOld) ); - Bac_ObjSetFanout( p, iOld, 0 ); -} - -/**Function************************************************************* - - Synopsis [Derives fanout.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_NtkDeriveFanout( Bac_Ntk_t * p ) -{ - int iCi, iCo; - assert( !Bac_NtkHasFanouts(p) ); - Bac_NtkStartFanouts( p ); - Bac_NtkForEachCo( p, iCo ) - { - assert( !Bac_ObjNextFanout(p, iCo) ); - iCi = Bac_ObjFanin(p, iCo); - if ( Bac_ObjFanout(p, iCi) ) - Bac_ObjSetNextFanout( p, Bac_ObjFanout(p, iCi), iCo ); - Bac_ObjSetFanout( p, iCi, iCo ); - } - Bac_NtkForEachCo( p, iCo ) - if ( !Bac_ObjNextFanout(p, iCo) ) - Bac_ObjSetFanout( p, Bac_ObjFanin(p, iCo), iCo ); -} -void Bac_ManDeriveFanout( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - Bac_NtkDeriveFanout( pNtk ); -} - -/**Function************************************************************* - - Synopsis [Assigns word-level names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ManAssignInternTwo( Bac_Ntk_t * p, int iNum, int nDigits, char * pPref, Vec_Int_t * vMap ) -{ - char Buffer[16]; int i, NameId = 0; - for ( i = 0; !NameId || Vec_IntEntry(vMap, NameId); i++ ) - { - if ( i == 0 ) - sprintf( Buffer, "%s%0*d", pPref, nDigits, iNum ); - else - sprintf( Buffer, "%s%0*d_%d", pPref, nDigits, iNum, i ); - NameId = Abc_NamStrFindOrAdd( p->pDesign->pStrs, Buffer, NULL ); - } - Vec_IntWriteEntry( vMap, NameId, 1 ); - return NameId; -} -int Bac_ManAssignCountNames( Bac_Ntk_t * p ) -{ - int i, iObj, iBox, Count = 0; - Bac_NtkForEachPiMain( p, iObj, i ) - if ( !Bac_ObjNameInt(p, iObj) ) - Count++; - Bac_NtkForEachBox( p, iBox ) - Bac_BoxForEachBoMain( p, iBox, iObj, i ) - if ( !Bac_ObjNameInt(p, iObj) ) - Count++; - return Count; -} -void Bac_ManAssignInternWordNamesNtk( Bac_Ntk_t * p, Vec_Int_t * vMap ) -{ - int k, iObj, iTerm, iName = -1, iBit = -1; - int nDigits, nPis = 0, nPos = 0, nNames = 1; - // start names - if ( !Bac_NtkHasNames(p) ) - Bac_NtkStartNames(p); - nDigits = Abc_Base10Log( Bac_ManAssignCountNames(p) ); - // populate map with the currently used names - Bac_NtkForEachCi( p, iObj ) - if ( Bac_ObjNameInt(p, iObj) ) - Vec_IntWriteEntry( vMap, Bac_ObjNameId(p, iObj), 1 ); - Bac_NtkForEachBox( p, iObj ) - if ( Bac_ObjNameInt(p, iObj) ) - Vec_IntWriteEntry( vMap, Bac_ObjNameId(p, iObj), 1 ); - // assign CI names - Bac_NtkForEachCi( p, iObj ) - { - if ( Bac_ObjNameInt(p, iObj) ) - { - iName = -1; - iBit = -1; - continue; - } - if ( Bac_ObjBit(p, iObj) ) - { - assert( iBit > 0 ); - Bac_ObjSetName( p, iObj, Abc_Var2Lit2(iBit++, BAC_NAME_INDEX) ); - } - else - { - //int Type = Bac_ObjType(p, iObj); - int Range = Bac_ObjIsPi(p, iObj) ? Bac_ObjPiRange(p, iObj) : Bac_BoxBoRange(p, iObj); - iName = Bac_ManAssignInternTwo( p, nNames++, nDigits, (char*)(Bac_ObjIsPi(p, iObj) ? "i":"n"), vMap ); - if ( Range == 1 ) - Bac_ObjSetName( p, iObj, Abc_Var2Lit2(iName, BAC_NAME_BIN) ); - else - Bac_ObjSetName( p, iObj, Abc_Var2Lit2(iName, BAC_NAME_WORD) ); - iBit = 1; - } - } - // transfer names to the interface - if ( Bac_NtkInfoNum(p) ) - { - for ( k = 0; k < Bac_NtkInfoNum(p); k++ ) - { - //char * pName = Bac_NtkName(p); - if ( Bac_NtkInfoType(p, k) == 1 ) // PI - { - iObj = Bac_NtkPi(p, nPis); - assert( !Bac_ObjBit(p, iObj) ); - assert( Bac_ObjNameType(p, iObj) <= BAC_NAME_WORD ); - Bac_NtkSetInfoName( p, k, Abc_Var2Lit2(Bac_ObjNameId(p, iObj), 1) ); - nPis += Bac_NtkInfoRange(p, k); - } - else if ( Bac_NtkInfoType(p, k) == 2 ) // PO - { - iObj = Bac_NtkPo(p, nPos); - assert( !Bac_ObjBit(p, iObj) ); - iObj = Bac_ObjFanin(p, iObj); - assert( Bac_ObjNameType(p, iObj) <= BAC_NAME_WORD ); - Bac_NtkSetInfoName( p, k, Abc_Var2Lit2(Bac_ObjNameId(p, iObj), 2) ); - nPos += Bac_NtkInfoRange(p, k); - } - else assert( 0 ); - } - assert( nPis == Bac_NtkPiNum(p) ); - assert( nPos == Bac_NtkPoNum(p) ); - } - // assign instance names - nDigits = Abc_Base10Log( Bac_NtkObjNum(p) ); - Bac_NtkForEachBox( p, iObj ) - if ( !Bac_ObjNameInt(p, iObj) ) - { - iName = Bac_ManAssignInternTwo( p, iObj, nDigits, "g", vMap ); - Bac_ObjSetName( p, iObj, Abc_Var2Lit2(iName, BAC_NAME_BIN) ); - } - // unmark all names - Bac_NtkForEachPi( p, iObj, k ) - if ( Bac_ObjNameType(p, iObj) <= BAC_NAME_WORD ) - Vec_IntWriteEntry( vMap, Bac_ObjNameId(p, iObj), 0 ); - Bac_NtkForEachBox( p, iObj ) - { - Vec_IntWriteEntry( vMap, Bac_ObjNameId(p, iObj), 0 ); - Bac_BoxForEachBo( p, iObj, iTerm, k ) - if ( Bac_ObjNameType(p, iTerm) <= BAC_NAME_WORD ) - Vec_IntWriteEntry( vMap, Bac_ObjNameId(p, iTerm), 0 ); - } -// printf( "Generated %d word-level names.\n", nNames-1 ); -} -void Bac_ManAssignInternWordNames( Bac_Man_t * p ) -{ - Vec_Int_t * vMap = Vec_IntStart( 2*Bac_ManObjNum(p) ); - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - Bac_ManAssignInternWordNamesNtk( pNtk, vMap ); - assert( Vec_IntCountEntry(vMap, 0) == Vec_IntSize(vMap) ); - Vec_IntFree( vMap ); -} - - -/**Function************************************************************* - - Synopsis [Count number of objects after collapsing.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ManClpObjNum_rec( Bac_Ntk_t * p ) -{ - int i, Counter = 0; - if ( p->Count >= 0 ) - return p->Count; - Bac_NtkForEachBox( p, i ) - Counter += Bac_ObjIsBoxUser(p, i) ? Bac_ManClpObjNum_rec( Bac_BoxNtk(p, i) ) + 3*Bac_BoxBoNum(p, i) : Bac_BoxSize(p, i); - return (p->Count = Counter); -} -int Bac_ManClpObjNum( Bac_Man_t * p ) -{ - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( p, pNtk, i ) - pNtk->Count = -1; - return Bac_NtkPioNum( Bac_ManRoot(p) ) + Bac_ManClpObjNum_rec( Bac_ManRoot(p) ); -} - -/**Function************************************************************* - - Synopsis [Collects boxes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_NtkDfs_rec( Bac_Ntk_t * p, int iObj, Vec_Int_t * vBoxes ) -{ - int k, iFanin; - if ( Bac_ObjIsBo(p, iObj) == 1 ) - { - Bac_NtkDfs_rec( p, Bac_ObjFanin(p, iObj), vBoxes ); - return; - } - assert( Bac_ObjIsPi(p, iObj) || Bac_ObjIsBox(p, iObj) ); - if ( Bac_ObjCopy(p, iObj) > 0 ) // visited - return; - Bac_ObjSetCopy( p, iObj, 1 ); - Bac_BoxForEachFanin( p, iObj, iFanin, k ) - Bac_NtkDfs_rec( p, iFanin, vBoxes ); - Vec_IntPush( vBoxes, iObj ); -} -Vec_Int_t * Bac_NtkDfs( Bac_Ntk_t * p ) -{ - int i, iObj; - Vec_Int_t * vBoxes = Vec_IntAlloc( Bac_NtkBoxNum(p) ); - Bac_NtkStartCopies( p ); // -1 = not visited; 1 = finished - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjSetCopy( p, iObj, 1 ); - Bac_NtkForEachPo( p, iObj, i ) - Bac_NtkDfs_rec( p, Bac_ObjFanin(p, iObj), vBoxes ); - return vBoxes; -} - -/**Function************************************************************* - - Synopsis [Collects user boxes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_NtkDfsUserBoxes_rec( Bac_Ntk_t * p, int iObj, Vec_Int_t * vBoxes ) -{ - int k, iFanin; - assert( Bac_ObjIsBoxUser(p, iObj) ); - if ( Bac_ObjCopy(p, iObj) == 1 ) // visited - return 1; - if ( Bac_ObjCopy(p, iObj) == 0 ) // loop - return 0; - Bac_ObjSetCopy( p, iObj, 0 ); - Bac_BoxForEachFanin( p, iObj, iFanin, k ) - if ( Bac_ObjIsBo(p, iFanin) && Bac_ObjIsBoxUser(p, Bac_ObjFanin(p, iFanin)) ) - if ( !Bac_NtkDfsUserBoxes_rec( p, Bac_ObjFanin(p, iFanin), vBoxes ) ) - return 0; - Vec_IntPush( vBoxes, iObj ); - Bac_ObjSetCopy( p, iObj, 1 ); - return 1; -} -int Bac_NtkDfsUserBoxes( Bac_Ntk_t * p ) -{ - int iObj; - Bac_NtkStartCopies( p ); // -1 = not visited; 0 = on the path; 1 = finished - Vec_IntClear( &p->vArray ); - Bac_NtkForEachBoxUser( p, iObj ) - if ( !Bac_NtkDfsUserBoxes_rec( p, iObj, &p->vArray ) ) - { - printf( "Cyclic dependency of user boxes is detected.\n" ); - return 0; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_NtkCollapse_rec( Bac_Ntk_t * pNew, Bac_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, iObj, iObjNew, iTerm; - Bac_NtkStartCopies( p ); - // set PI copies - assert( Vec_IntSize(vSigs) == Bac_NtkPiNum(p) ); - Bac_NtkForEachPi( p, iObj, i ) - Bac_ObjSetCopy( p, iObj, Vec_IntEntry(vSigs, i) ); - // duplicate internal objects and create buffers for hierarchy instances - Bac_NtkForEachBox( p, iObj ) - if ( Bac_ObjIsBoxPrim( p, iObj ) ) - Bac_BoxDup( pNew, p, iObj ); - else - { - Bac_BoxForEachBo( p, iObj, iTerm, i ) - { - iObjNew = Bac_ObjAlloc( pNew, BAC_OBJ_BI, -1 ); - iObjNew = Bac_ObjAlloc( pNew, BAC_BOX_BUF, -1 ); // buffer - iObjNew = Bac_ObjAlloc( pNew, BAC_OBJ_BO, -1 ); - Bac_ObjSetCopy( p, iTerm, iObjNew ); - } - } - // duplicate user modules and connect objects - Bac_NtkForEachBox( p, iObj ) - if ( Bac_ObjIsBoxPrim( p, iObj ) ) - { - Bac_BoxForEachBi( p, iObj, iTerm, i ) - Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iTerm), Bac_ObjCopy(p, Bac_ObjFanin(p, iTerm)) ); - } - else - { - Vec_IntClear( vSigs ); - Bac_BoxForEachBi( p, iObj, iTerm, i ) - Vec_IntPush( vSigs, Bac_ObjCopy(p, Bac_ObjFanin(p, iTerm)) ); - Bac_NtkCollapse_rec( pNew, Bac_BoxNtk(p, iObj), vSigs ); - assert( Vec_IntSize(vSigs) == Bac_BoxBoNum(p, iObj) ); - Bac_BoxForEachBo( p, iObj, iTerm, i ) - Bac_ObjSetFanin( pNew, Bac_ObjCopy(p, iTerm)-2, Vec_IntEntry(vSigs, i) ); - } - // collect POs - Vec_IntClear( vSigs ); - Bac_NtkForEachPo( p, iObj, i ) - Vec_IntPush( vSigs, Bac_ObjCopy(p, Bac_ObjFanin(p, iObj)) ); -} -Bac_Man_t * Bac_ManCollapse( Bac_Man_t * p ) -{ - int i, iObj; - Vec_Int_t * vSigs = Vec_IntAlloc( 1000 ); - Bac_Man_t * pNew = Bac_ManStart( p, 1 ); - Bac_Ntk_t * pRoot = Bac_ManRoot( p ); - Bac_Ntk_t * pRootNew = Bac_ManRoot( pNew ); - Bac_NtkAlloc( pRootNew, Bac_NtkNameId(pRoot), Bac_NtkPiNum(pRoot), Bac_NtkPoNum(pRoot), Bac_ManClpObjNum(p) ); - if ( Vec_IntSize(&pRoot->vInfo) ) - Vec_IntAppend( &pRootNew->vInfo, &pRoot->vInfo ); - Bac_NtkForEachPi( pRoot, iObj, i ) - Vec_IntPush( vSigs, Bac_ObjAlloc(pRootNew, BAC_OBJ_PI, -1) ); - Bac_NtkCollapse_rec( pRootNew, pRoot, vSigs ); - assert( Vec_IntSize(vSigs) == Bac_NtkPoNum(pRoot) ); - Bac_NtkForEachPo( pRoot, iObj, i ) - Bac_ObjAlloc( pRootNew, BAC_OBJ_PO, Vec_IntEntry(vSigs, i) ); - assert( Bac_NtkObjNum(pRootNew) == Bac_NtkObjNumAlloc(pRootNew) ); - Vec_IntFree( vSigs ); - // transfer PI/PO names - if ( Bac_NtkHasNames(pRoot) ) - { - Bac_NtkStartNames( pRootNew ); - Bac_NtkForEachPi( pRoot, iObj, i ) - Bac_ObjSetName( pRootNew, Bac_NtkPi(pRootNew, i), Bac_ObjName(pRoot, iObj) ); - Bac_NtkForEachPoDriver( pRoot, iObj, i ) - if ( !Bac_ObjIsPi(pRoot, iObj) ) - Bac_ObjSetName( pRootNew, Bac_ObjCopy(pRoot, iObj), Bac_ObjName(pRoot, iObj) ); - } - return pNew; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END diff --git a/src/base/bac/bacOper.c b/src/base/bac/bacOper.c deleted file mode 100644 index 0550eca67..000000000 --- a/src/base/bac/bacOper.c +++ /dev/null @@ -1,365 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacOper.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Operator procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacOper.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_BoxCreate( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vFanins, int nInA, int nInB, int nOuts ) -{ - char pName[100]; int i, iObj, iFanin; - assert( BAC_OBJ_BOX < Type && Type < BAC_BOX_UNKNOWN ); - if ( BAC_BOX_CF <= Type && Type <= BAC_BOX_CZ ) - { - sprintf( pName, "ABCCTo%d", nOuts ); - assert( 0 == Vec_IntSize(vFanins) ); - iObj = Bac_BoxAlloc( p, Type, 0, nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV ) - { - char * pPref[2] = { "ABCBUF", "ABCINV" }; - assert( nInA == nOuts ); - assert( nInA == Vec_IntSize(vFanins) ); - sprintf( pName, "%sa%do%d", pPref[Type - BAC_BOX_BUF], nInA, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR ) - { - char * pPref[6] = { "ABCAND", "ABCNAND", "ABCOR", "ABCNOR", "ABCXOR", "ABCXNOR" }; - assert( nInA == nOuts && nInB == nOuts ); - assert( nInA + nInB == Vec_IntSize(vFanins) ); - sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_AND], nInA, nInB, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( Type == BAC_BOX_MUX ) - { - char * pPref[1] = { "ABCMUX" }; - assert( nInA == nOuts && nInB == nOuts ); - assert( 1 + nInA + nInB == Vec_IntSize(vFanins) ); - sprintf( pName, "%sc%da%db%do%d", pPref[Type - BAC_BOX_MUX], 1, nInA, nInB, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( Type == BAC_BOX_MAJ ) - { - char * pPref[1] = { "ABCMAJ" }; - assert( nInA == 1 && nInB == 1 && nOuts == 1 ); - assert( 3 == Vec_IntSize(vFanins) ); - sprintf( pName, "%sa%db%dc%do%d", pPref[Type - BAC_BOX_MAJ], 1, 1, 1, 1 ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( BAC_BOX_RAND <= Type && Type <= BAC_BOX_RXNOR ) - { - char * pPref[6] = { "ABCRAND", "ABCRNAND", "ABCROR", "ABCRNOR", "ABCRXOR", "ABCRXNOR" }; - assert( nInA == nInB && 1 == nOuts ); - assert( nInA + nInB == Vec_IntSize(vFanins) ); - sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_RAND], nInA, nInB, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( Type == BAC_BOX_SEL ) - { - char * pPref[1] = { "ABCSEL" }; - assert( nInA * nOuts == nInB ); - assert( nInA + nInB == Vec_IntSize(vFanins) ); - sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_SEL], nInA, nInB, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - else if ( Type == BAC_BOX_PSEL ) - { - char * pPref[1] = { "ABCPSEL" }; - assert( nInA * nOuts == nInB ); - assert( 1 + nInA + nInB == Vec_IntSize(vFanins) ); - sprintf( pName, "%si%da%db%do%d", pPref[Type - BAC_BOX_SEL], 1, nInA, nInB, nOuts ); - iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) ); - } - // add fanins - Vec_IntForEachEntry( vFanins, iFanin, i ) - Bac_ObjSetFanin( p, Bac_BoxBi(p, iObj, i), iFanin ); - return iObj; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ObjClpWide( Bac_Ntk_t * p, int iBox ) -{ - Bac_ObjType_t Type = Bac_ObjType( p, iBox ); - int nBis = Bac_BoxBiNum(p, iBox); - int nBos = Bac_BoxBoNum(p, iBox); - int i, k, iObj; - assert( nBos > 1 ); - Vec_IntClear( &p->vArray ); - if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV ) - { - for ( i = 0; i < nBos; i++ ) - { - Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, i) ); - iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, -1, 1 ); - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) ); - } - } - else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR ) - { - assert( nBis == 2 * nBos ); - for ( i = 0; i < nBos; i++ ) - { - Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, iBox, i), Bac_BoxFanin(p, iBox, nBos+i) ); - iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 ); - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) ); - } - } - else if ( Type == BAC_BOX_MUX ) - { - assert( nBis - 1 == 2 * nBos ); - for ( i = 0; i < nBos; i++ ) - { - Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, 0) ); - Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBos+i) ); - iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 ); - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) ); - } - } - else if ( Type == BAC_BOX_NMUX ) - { - int n, nIns = nBis / nBos; - assert( nBis % nBos == 0 ); - for ( n = 1; n < 32; n++ ) - if ( n + (1 << n) == nIns ) - break; - assert( n > 1 && n < 32 ); - for ( i = 0; i < nBos; i++ ) - { - Vec_IntClear( &p->vArray2 ); - for ( k = 0; k < n; k++ ) - Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, k) ); - for ( k = 0; k < (1 << n); k++ ) - Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, n + (1 << n) * i + k) ); - iObj = Bac_BoxCreate( p, Type, &p->vArray2, n, (1 << n), 1 ); - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) ); - } - } - else if ( Type == BAC_BOX_SEL ) - { - } - else if ( Type == BAC_BOX_PSEL ) - { - } - else if ( Type == BAC_BOX_DFF || Type == BAC_BOX_LATCH ) - { - } - else if ( Type == BAC_BOX_DFFRS || Type == BAC_BOX_LATCHRS ) - { - } - else assert( 0 ); - Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) ); - return iBox; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ObjClpArith( Bac_Ntk_t * p, int iBox ) -{ - Bac_ObjType_t Type = Bac_ObjType( p, iBox ); - int i, iObj = -1; - int nBis = 0;//Bac_NtkReadRangesPrim( Bac_BoxNtkName(p, iObj), &p->vArray, 0 ); - assert( nBis == Bac_BoxBiNum(p, iBox) ); - if ( Type == BAC_BOX_ADD ) - { - int Carry = Bac_BoxFanin(p, iBox, 0); - int nBits = Vec_IntEntry(&p->vArray, 1); - assert( Vec_IntSize(&p->vArray) == 3 ); - assert( Vec_IntEntry(&p->vArray, 0) == 1 ); - assert( Vec_IntEntry(&p->vArray, 2) == nBits ); - Vec_IntClear( &p->vArray ); - for ( i = 0; i < nBits; i++ ) - { - Vec_IntFill( &p->vArray2, 1, Carry ); - Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBits+i) ); - iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, 1, 1, 1 ); - Carry = Bac_BoxBo(p, iObj, 1); - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) ); - } - Vec_IntPush( &p->vArray, Carry ); - } - else if ( Type == BAC_BOX_SUB ) - { - int iConst, nBits = Vec_IntEntry(&p->vArray, 0); - assert( Vec_IntSize(&p->vArray) == 2 ); - assert( Vec_IntEntry(&p->vArray, 1) == nBits ); - // create inverter - Vec_IntClear( &p->vArray2 ); - for ( i = 0; i < nBits; i++ ) - Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, nBits+i) ); - iObj = Bac_BoxCreate( p, BAC_BOX_INV, &p->vArray2, nBits, -1, nBits ); - // create constant - Vec_IntClear( &p->vArray2 ); - iConst = Bac_BoxCreate( p, BAC_BOX_CT, &p->vArray2, -1, -1, 1 ); - // collect fanins - Vec_IntFill( &p->vArray2, 1, iConst+1 ); - for ( i = 0; i < nBits; i++ ) - Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, i) ); - for ( i = 0; i < nBits; i++ ) - Vec_IntPush( &p->vArray2, Bac_BoxBo(p, iObj, i) ); - // create adder - iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, nBits, nBits, nBits ); - // collect fanins - Vec_IntClear( &p->vArray ); - for ( i = 0; i < nBits; i++ ) - Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, i) ); - } - else if ( Type == BAC_BOX_MUL ) - { - } - else if ( Type == BAC_BOX_DIV ) - { - } - else if ( Type == BAC_BOX_MOD ) - { - } - else if ( Type == BAC_BOX_REM ) - { - } - else if ( Type == BAC_BOX_POW ) - { - } - else if ( Type == BAC_BOX_MIN ) - { - } - else if ( Type == BAC_BOX_ABS ) - { - } - - else if ( Type == BAC_BOX_LTHAN ) - { - } - else if ( Type == BAC_BOX_LETHAN ) - { - } - else if ( Type == BAC_BOX_METHAN ) - { - } - else if ( Type == BAC_BOX_MTHAN ) - { - } - else if ( Type == BAC_BOX_EQU ) - { - } - else if ( Type == BAC_BOX_NEQU ) - { - } - - else if ( Type == BAC_BOX_SHIL ) - { - } - else if ( Type == BAC_BOX_SHIR ) - { - } - else if ( Type == BAC_BOX_ROTL ) - { - } - else if ( Type == BAC_BOX_ROTR ) - { - } - Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) ); - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_ObjClpMemory( Bac_Ntk_t * p, int iBox ) -{ - int i, En, iNext, nItems = Bac_BoxBiNum(p, iBox); - assert( Bac_ObjType(p, iBox) == BAC_BOX_RAMBOX ); - assert( Bac_BoxBiNum(p, iBox) == Bac_BoxBoNum(p, iBox) ); - // for each fanin of RAMBOX, make sure address width is the same - Bac_BoxForEachFaninBox( p, iBox, iNext, i ) - assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMWC ); - - // create decoders, selectors and flops - for ( i = 0; i < nItems; i++ ) - { - int BoxW = Bac_ObjFanin(p, Bac_BoxBi(p, iBox, i)); - int BoxR = Bac_ObjFanout(p, Bac_BoxBo(p, iBox, 0)); - assert( Bac_ObjType(p, BoxW) == BAC_BOX_RAMWC ); - assert( Bac_ObjType(p, BoxR) == BAC_BOX_RAMR ); - // create enable - Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, BoxW, 1), Bac_BoxFanin(p, BoxR, 0) ); - En = Bac_BoxCreate( p, BAC_BOX_AND, &p->vArray2, 1, 1, 1 ); - En = Bac_BoxBo( p, En, 0 ); - // collect address - } - // for each fanout of RAMBOX, makes ure address width is the same -// Bac_BoxForEachFanoutBox( p, iBox, iNext, i ) -// assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMR ); - // create selectors and connect them - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacPrs.h b/src/base/bac/bacPrs.h deleted file mode 100644 index d45bceec7..000000000 --- a/src/base/bac/bacPrs.h +++ /dev/null @@ -1,363 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacPrs.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Parser declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacPrs.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef ABC__base__prs__prs_h -#define ABC__base__prs__prs_h - - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include "aig/gia/gia.h" -#include "misc/util/utilNam.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -// parser name types -typedef enum { - BAC_PRS_NAME = 0, // 0: name/variable - BAC_PRS_SLICE, // 1: slice - BAC_PRS_CONST, // 2: constant - BAC_PRS_CONCAT, // 3: concatentation -} Psr_ManType_t; - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -// network -typedef struct Psr_Ntk_t_ Psr_Ntk_t; -struct Psr_Ntk_t_ -{ - // general info - int iModuleName; - unsigned fMapped : 1; - unsigned fSlices : 1; - unsigned fHasC0s : 1; - unsigned fHasC1s : 1; - unsigned fHasCXs : 1; - unsigned fHasCZs : 1; - Abc_Nam_t * pStrs; - // interface - Vec_Int_t vOrder; // order of signals - // signal names - Vec_Int_t vInouts; // inouts - Vec_Int_t vInputs; // inputs - Vec_Int_t vOutputs; // outputs - Vec_Int_t vWires; // wires - // signal ranges - Vec_Int_t vInoutsR; // inouts - Vec_Int_t vInputsR; // inputs - Vec_Int_t vOutputsR; // outputs - Vec_Int_t vWiresR; // wires - // slices/concatenations/objects - Vec_Int_t vSlices; // NameId + RangeId - Vec_Int_t vConcats; // array of NameId/SliceId/ConstId - Vec_Int_t vBoxes; // ModuleId + InstId + array of pairs {FormNameId, ActSignalId(NameId/SliceId/ConstId/ConcatId)} - Vec_Int_t vObjs; // box handles -}; - -// parser -typedef struct Psr_Man_t_ Psr_Man_t; -struct Psr_Man_t_ -{ - // input data - char * pName; // file name - char * pBuffer; // file contents - char * pLimit; // end of file - char * pCur; // current position - Abc_Nam_t * pStrs; // string manager - Psr_Ntk_t * pNtk; // current network - Vec_Ptr_t * vNtks; // input networks - // temporary data - Vec_Str_t vCover; // one SOP cover - Vec_Int_t vTemp; // array of tokens - Vec_Int_t vTemp2; // array of tokens - // statistics - Vec_Int_t vKnown; - Vec_Int_t vFailed; - Vec_Int_t vSucceeded; - // error handling - int fUsingTemp2; // vTemp2 is in use - char ErrorStr[1000]; // error -}; - -static inline Psr_Ntk_t * Psr_ManNtk( Vec_Ptr_t * vPrs, int i ) { return i >= 0 && i < Vec_PtrSize(vPrs) ? (Psr_Ntk_t *)Vec_PtrEntry(vPrs, i) : NULL; } -static inline Psr_Ntk_t * Psr_ManRoot( Vec_Ptr_t * vPrs ) { return Psr_ManNtk(vPrs, 0); } -static inline Abc_Nam_t * Psr_ManNameMan( Vec_Ptr_t * vPrs ) { return Psr_ManRoot(vPrs)->pStrs; } - -static inline int Psr_NtkId( Psr_Ntk_t * p ) { return p->iModuleName; } -static inline int Psr_NtkPioNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vInouts); } -static inline int Psr_NtkPiNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); } -static inline int Psr_NtkPoNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); } -static inline int Psr_NtkBoxNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vObjs); } -static inline int Psr_NtkObjNum( Psr_Ntk_t * p ) { return Psr_NtkPioNum(p) + Psr_NtkPiNum(p) + Psr_NtkPoNum(p) + Psr_NtkBoxNum(p); } -static inline char * Psr_NtkStr( Psr_Ntk_t * p, int h ) { return Abc_NamStr(p->pStrs, h); } -static inline char * Psr_NtkName( Psr_Ntk_t * p ) { return Psr_NtkStr(p, Psr_NtkId(p)); } -static inline int Psr_NtkSigName( Psr_Ntk_t * p, int i ) { if (!p->fSlices) return i; assert(Abc_Lit2Att2(i) == BAC_PRS_NAME); return Abc_Lit2Var2(i); } - -static inline int Psr_SliceName( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h); } -static inline int Psr_SliceRange( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h+1); } - -static inline int Psr_CatSize( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vConcats, h); } -static inline int * Psr_CatArray( Psr_Ntk_t * p, int h ) { return Vec_IntEntryP(&p->vConcats, h+1); } -static inline Vec_Int_t * Psr_CatSignals( Psr_Ntk_t * p, int h ) { static Vec_Int_t V; V.nSize = V.nCap = Psr_CatSize(p, h); V.pArray = Psr_CatArray(p, h); return &V; } - -static inline int Psr_BoxHand( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vObjs, i); } -static inline int Psr_BoxSize( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i))-2; } -static inline int Psr_BoxIONum( Psr_Ntk_t * p, int i ) { return Psr_BoxSize(p, i) / 2; } -static inline int Psr_BoxNtk( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+1); } -static inline void Psr_BoxSetNtk( Psr_Ntk_t * p, int i, int m ) { Vec_IntWriteEntry(&p->vBoxes, Psr_BoxHand(p, i)+1, m); } -static inline int Psr_BoxName( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+2); } -static inline int Psr_BoxIsNode( Psr_Ntk_t * p, int i ) { return!Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+3); } // no formal names -static inline int * Psr_BoxArray( Psr_Ntk_t * p, int i ) { return Vec_IntEntryP(&p->vBoxes, Psr_BoxHand(p, i)+3); } -static inline Vec_Int_t * Psr_BoxSignals( Psr_Ntk_t * p, int i ) { static Vec_Int_t V; V.nSize = V.nCap = Psr_BoxSize(p, i); V.pArray = Psr_BoxArray(p, i); return &V; } - -#define Psr_ManForEachNameVec( vVec, p, pName, i ) \ - for ( i = 0; (i < Vec_IntSize(vVec)) && ((pName) = Abc_NamStr(p->pStrs, Vec_IntEntry(vVec,i))); i++ ) - -#define Psr_NtkForEachPio( p, NameId, i ) \ - for ( i = 0; i < Psr_NtkPioNum(p) && ((NameId) = Vec_IntEntry(&p->vInouts, i)); i++ ) -#define Psr_NtkForEachPi( p, NameId, i ) \ - for ( i = 0; i < Psr_NtkPiNum(p) && ((NameId) = Vec_IntEntry(&p->vInputs, i)); i++ ) -#define Psr_NtkForEachPo( p, NameId, i ) \ - for ( i = 0; i < Psr_NtkPoNum(p) && ((NameId) = Vec_IntEntry(&p->vOutputs, i)); i++ ) -#define Psr_NtkForEachBox( p, vVec, i ) \ - for ( i = 0; i < Psr_NtkBoxNum(p) && ((vVec) = Psr_BoxSignals(p, i)); i++ ) - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -// create error message -static inline int Psr_ManErrorSet( Psr_Man_t * p, char * pError, int Value ) -{ - assert( !p->ErrorStr[0] ); - sprintf( p->ErrorStr, "%s", pError ); - return Value; -} -// clear error message -static inline void Psr_ManErrorClear( Psr_Man_t * p ) -{ - p->ErrorStr[0] = '\0'; -} -// print error message -static inline int Psr_ManErrorPrint( Psr_Man_t * p ) -{ - char * pThis; int iLine = 0; - if ( !p->ErrorStr[0] ) return 1; - for ( pThis = p->pBuffer; pThis < p->pCur; pThis++ ) - iLine += (int)(*pThis == '\n'); - printf( "Line %d: %s\n", iLine, p->ErrorStr ); - return 0; -} - -// parsing network -static inline void Psr_ManInitializeNtk( Psr_Man_t * p, int iName, int fSlices ) -{ - assert( p->pNtk == NULL ); - p->pNtk = ABC_CALLOC( Psr_Ntk_t, 1 ); - p->pNtk->iModuleName = iName; - p->pNtk->fSlices = fSlices; - p->pNtk->pStrs = Abc_NamRef( p->pStrs ); - Vec_PtrPush( p->vNtks, p->pNtk ); -} -static inline void Psr_ManFinalizeNtk( Psr_Man_t * p ) -{ - assert( p->pNtk != NULL ); - p->pNtk = NULL; -} - -// parsing slice/concatentation/box -static inline int Psr_NtkAddSlice( Psr_Ntk_t * p, int Name, int Range ) -{ - int Value = Vec_IntSize(&p->vSlices); - Vec_IntPushTwo( &p->vSlices, Name, Range ); - return Value; -} -static inline int Psr_NtkAddConcat( Psr_Ntk_t * p, Vec_Int_t * vTemp ) -{ - int Value; - if ( !(Vec_IntSize(&p->vConcats) & 1) ) - Vec_IntPush(&p->vConcats, -1); - Value = Vec_IntSize(&p->vConcats); - assert( Value & 1 ); - Vec_IntPush( &p->vConcats, Vec_IntSize(vTemp) ); - Vec_IntAppend( &p->vConcats, vTemp ); - return Value; -} -static inline void Psr_NtkAddBox( Psr_Ntk_t * p, int ModName, int InstName, Vec_Int_t * vTemp ) -{ - int Value; - assert( Vec_IntSize(vTemp) % 2 == 0 ); - if ( !(Vec_IntSize(&p->vBoxes) & 1) ) - Vec_IntPush(&p->vBoxes, -1); - Value = Vec_IntSize(&p->vBoxes); - assert( Value & 1 ); - Vec_IntPush( &p->vObjs, Value ); - // create entry - Vec_IntPush( &p->vBoxes, Vec_IntSize(vTemp)+2 ); - Vec_IntPush( &p->vBoxes, ModName ); - Vec_IntPush( &p->vBoxes, InstName ); - Vec_IntAppend( &p->vBoxes, vTemp ); -} - - -static inline char * Psr_ManLoadFile( char * pFileName, char ** ppLimit ) -{ - char * pBuffer; - int nFileSize, RetValue; - FILE * pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - printf( "Cannot open input file.\n" ); - return NULL; - } - // get the file size, in bytes - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - // move the file current reading position to the beginning - rewind( pFile ); - // load the contents of the file into memory - pBuffer = ABC_ALLOC( char, nFileSize + 16 ); - pBuffer[0] = '\n'; - RetValue = fread( pBuffer+1, nFileSize, 1, pFile ); - fclose( pFile ); - // terminate the string with '\0' - pBuffer[nFileSize + 1] = '\n'; - pBuffer[nFileSize + 2] = '\0'; - *ppLimit = pBuffer + nFileSize + 3; - return pBuffer; -} -static inline Psr_Man_t * Psr_ManAlloc( char * pFileName ) -{ - Psr_Man_t * p; - char * pBuffer, * pLimit; - pBuffer = Psr_ManLoadFile( pFileName, &pLimit ); - if ( pBuffer == NULL ) - return NULL; - p = ABC_CALLOC( Psr_Man_t, 1 ); - p->pName = pFileName; - p->pBuffer = pBuffer; - p->pLimit = pLimit; - p->pCur = pBuffer; - p->pStrs = Abc_NamStart( 1000, 24 ); - p->vNtks = Vec_PtrAlloc( 100 ); - return p; -} - -static inline void Psr_NtkFree( Psr_Ntk_t * p ) -{ - if ( p->pStrs ) - Abc_NamDeref( p->pStrs ); - Vec_IntErase( &p->vOrder ); - Vec_IntErase( &p->vInouts ); - Vec_IntErase( &p->vInputs ); - Vec_IntErase( &p->vOutputs ); - Vec_IntErase( &p->vWires ); - Vec_IntErase( &p->vInoutsR ); - Vec_IntErase( &p->vInputsR ); - Vec_IntErase( &p->vOutputsR ); - Vec_IntErase( &p->vWiresR ); - Vec_IntErase( &p->vSlices ); - Vec_IntErase( &p->vConcats ); - Vec_IntErase( &p->vBoxes ); - Vec_IntErase( &p->vObjs ); - ABC_FREE( p ); -} - -static inline void Psr_ManVecFree( Vec_Ptr_t * vPrs ) -{ - Psr_Ntk_t * pNtk; int i; - Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i ) - Psr_NtkFree( pNtk ); - Vec_PtrFree( vPrs ); -} - -static inline void Psr_ManFree( Psr_Man_t * p ) -{ - if ( p->pStrs ) - Abc_NamDeref( p->pStrs ); - if ( p->vNtks ) - Psr_ManVecFree( p->vNtks ); - // temporary - Vec_StrErase( &p->vCover ); - Vec_IntErase( &p->vTemp ); - Vec_IntErase( &p->vTemp2 ); - Vec_IntErase( &p->vKnown ); - Vec_IntErase( &p->vFailed ); - Vec_IntErase( &p->vSucceeded ); - ABC_FREE( p->pBuffer ); - ABC_FREE( p ); -} - -static inline int Psr_NtkMemory( Psr_Ntk_t * p ) -{ - int nMem = sizeof(Psr_Ntk_t); - nMem += Vec_IntMemory( &p->vOrder ); - nMem += Vec_IntMemory( &p->vInouts ); - nMem += Vec_IntMemory( &p->vInputs ); - nMem += Vec_IntMemory( &p->vOutputs ); - nMem += Vec_IntMemory( &p->vWires ); - nMem += Vec_IntMemory( &p->vInoutsR ); - nMem += Vec_IntMemory( &p->vInputsR ); - nMem += Vec_IntMemory( &p->vOutputsR ); - nMem += Vec_IntMemory( &p->vWiresR ); - nMem += Vec_IntMemory( &p->vSlices ); - nMem += Vec_IntMemory( &p->vBoxes ); - nMem += Vec_IntMemory( &p->vConcats ); - return nMem; -} -static inline int Psr_ManMemory( Vec_Ptr_t * vPrs ) -{ - Psr_Ntk_t * pNtk; int i; - int nMem = Vec_PtrMemory(vPrs); - Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i ) - nMem += Psr_NtkMemory( pNtk ); - nMem += Abc_NamMemUsed(Psr_ManNameMan(vPrs)); - return nMem; -} - - - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/*=== bac.c ========================================================*/ - - -ABC_NAMESPACE_HEADER_END - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/base/bac/bacPrsBuild.c b/src/base/bac/bacPrsBuild.c deleted file mode 100644 index e5c9c3540..000000000 --- a/src/base/bac/bacPrsBuild.c +++ /dev/null @@ -1,356 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacPrsBuild.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Parse tree to netlist transformation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacPrsBuild.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" -#include "map/mio/mio.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Psr_ManIsMapped( Psr_Ntk_t * pNtk ) -{ - Vec_Int_t * vSigs; int iBox; - Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - if ( pLib == NULL ) - return 0; - Psr_NtkForEachBox( pNtk, vSigs, iBox ) - if ( !Psr_BoxIsNode(pNtk, iBox) ) - { - int NtkId = Psr_BoxNtk( pNtk, iBox ); - if ( Mio_LibraryReadGateByName(pLib, Psr_NtkStr(pNtk, NtkId), NULL) ) - return 1; - } - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Psr_NtkCountObjects( Psr_Ntk_t * pNtk ) -{ - Vec_Int_t * vFanins; - int i, Count = Psr_NtkObjNum(pNtk); - Psr_NtkForEachBox( pNtk, vFanins, i ) - Count += Psr_BoxIONum(pNtk, i); - return Count; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -// replaces NameIds of formal names by their index in the box model -void Psr_ManRemapOne( Vec_Int_t * vSigs, Psr_Ntk_t * pNtkBox, Vec_Int_t * vMap ) -{ - int i, NameId; - // map formal names into I/O indexes - Psr_NtkForEachPi( pNtkBox, NameId, i ) - { - assert( Vec_IntEntry(vMap, NameId) == -1 ); - Vec_IntWriteEntry( vMap, NameId, i + 1 ); // +1 to keep 1st form input non-zero - } - Psr_NtkForEachPo( pNtkBox, NameId, i ) - { - assert( Vec_IntEntry(vMap, NameId) == -1 ); - Vec_IntWriteEntry( vMap, NameId, Psr_NtkPiNum(pNtkBox) + i + 1 ); // +1 to keep 1st form input non-zero - } - // remap box - assert( Vec_IntSize(vSigs) % 2 == 0 ); - Vec_IntForEachEntry( vSigs, NameId, i ) - { - assert( Vec_IntEntry(vMap, NameId) != -1 ); - Vec_IntWriteEntry( vSigs, i++, Vec_IntEntry(vMap, NameId) ); - } - // unmap formal inputs - Psr_NtkForEachPi( pNtkBox, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); - Psr_NtkForEachPo( pNtkBox, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); -} -void Psr_ManRemapGate( Vec_Int_t * vSigs ) -{ - int i, FormId; - Vec_IntForEachEntry( vSigs, FormId, i ) - Vec_IntWriteEntry( vSigs, i, i/2 + 1 ), i++; -} -void Psr_ManRemapBoxes( Bac_Man_t * pNew, Vec_Ptr_t * vDes, Psr_Ntk_t * pNtk, Vec_Int_t * vMap ) -{ - Vec_Int_t * vSigs; int iBox; - Psr_NtkForEachBox( pNtk, vSigs, iBox ) - if ( !Psr_BoxIsNode(pNtk, iBox) ) - { - int NtkId = Psr_BoxNtk( pNtk, iBox ); - int NtkIdNew = Bac_ManNtkFindId( pNew, Psr_NtkStr(pNtk, NtkId) ); - assert( NtkIdNew > 0 ); - Psr_BoxSetNtk( pNtk, iBox, NtkIdNew ); - if ( NtkIdNew <= Bac_ManNtkNum(pNew) ) - Psr_ManRemapOne( vSigs, Psr_ManNtk(vDes, NtkIdNew-1), vMap ); - //else - // Psr_ManRemapGate( vSigs ); - } -} -void Psr_ManCleanMap( Psr_Ntk_t * pNtk, Vec_Int_t * vMap ) -{ - Vec_Int_t * vSigs; - int i, k, NameId, Sig; - Psr_NtkForEachPi( pNtk, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); - Psr_NtkForEachBox( pNtk, vSigs, i ) - Vec_IntForEachEntryDouble( vSigs, NameId, Sig, k ) - Vec_IntWriteEntry( vMap, Psr_NtkSigName(pNtk, Sig), -1 ); - Psr_NtkForEachPo( pNtk, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); -} -// create maps of NameId and boxes -void Psr_ManBuildNtk( Bac_Ntk_t * pNew, Vec_Ptr_t * vDes, Psr_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes ) -{ - Psr_Ntk_t * pNtkBox; Vec_Int_t * vSigs; int iBox; - int i, Index, NameId, iObj, iConst0, iTerm; - int iNonDriven = -1, nNonDriven = 0; - assert( Psr_NtkPioNum(pNtk) == 0 ); - Psr_ManRemapBoxes( pNew->pDesign, vDes, pNtk, vMap ); - Bac_NtkStartNames( pNew ); - // create primary inputs - Psr_NtkForEachPi( pNtk, NameId, i ) - { - if ( Vec_IntEntry(vMap, NameId) != -1 ) - printf( "Primary inputs %d and %d have the same name.\n", Vec_IntEntry(vMap, NameId), i ); - iObj = Bac_ObjAlloc( pNew, BAC_OBJ_PI, -1 ); - Bac_ObjSetName( pNew, iObj, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntWriteEntry( vMap, NameId, iObj ); - } - // create box outputs - Vec_IntClear( vBoxes ); - Psr_NtkForEachBox( pNtk, vSigs, iBox ) - if ( !Psr_BoxIsNode(pNtk, iBox) ) - { - pNtkBox = Psr_ManNtk( vDes, Psr_BoxNtk(pNtk, iBox)-1 ); - if ( pNtkBox == NULL ) - { - iObj = Bac_BoxAlloc( pNew, BAC_BOX_GATE, Vec_IntSize(vSigs)/2-1, 1, Psr_BoxNtk(pNtk, iBox) ); - Bac_ObjSetName( pNew, iObj, Abc_Var2Lit2(Psr_BoxName(pNtk, iBox), BAC_NAME_BIN) ); - // consider box output - NameId = Vec_IntEntryLast( vSigs ); - NameId = Psr_NtkSigName( pNtk, NameId ); - if ( Vec_IntEntry(vMap, NameId) != -1 ) - printf( "Box output name %d is already driven.\n", NameId ); - iTerm = Bac_BoxBo( pNew, iObj, 0 ); - Bac_ObjSetName( pNew, iTerm, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntWriteEntry( vMap, NameId, iTerm ); - } - else - { - iObj = Bac_BoxAlloc( pNew, BAC_OBJ_BOX, Psr_NtkPiNum(pNtkBox), Psr_NtkPoNum(pNtkBox), Psr_BoxNtk(pNtk, iBox) ); - Bac_ObjSetName( pNew, iObj, Abc_Var2Lit2(Psr_BoxName(pNtk, iBox), BAC_NAME_BIN) ); - Bac_NtkSetHost( Bac_ManNtk(pNew->pDesign, Psr_BoxNtk(pNtk, iBox)), Bac_NtkId(pNew), iObj ); - Vec_IntForEachEntry( vSigs, Index, i ) - { - i++; - if ( --Index < Psr_NtkPiNum(pNtkBox) ) - continue; - assert( Index - Psr_NtkPiNum(pNtkBox) < Psr_NtkPoNum(pNtkBox) ); - // consider box output - NameId = Vec_IntEntry( vSigs, i ); - NameId = Psr_NtkSigName( pNtk, NameId ); - if ( Vec_IntEntry(vMap, NameId) != -1 ) - printf( "Box output name %d is already driven.\n", NameId ); - iTerm = Bac_BoxBo( pNew, iObj, Index - Psr_NtkPiNum(pNtkBox) ); - Bac_ObjSetName( pNew, iTerm, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntWriteEntry( vMap, NameId, iTerm ); - } - } - // remember box - Vec_IntPush( vBoxes, iObj ); - } - else - { - iObj = Bac_BoxAlloc( pNew, (Bac_ObjType_t)Psr_BoxNtk(pNtk, iBox), Psr_BoxIONum(pNtk, iBox)-1, 1, -1 ); - // consider box output - NameId = Vec_IntEntryLast( vSigs ); - NameId = Psr_NtkSigName( pNtk, NameId ); - if ( Vec_IntEntry(vMap, NameId) != -1 ) - printf( "Node output name %d is already driven.\n", NameId ); - iTerm = Bac_BoxBo( pNew, iObj, 0 ); - Bac_ObjSetName( pNew, iTerm, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntWriteEntry( vMap, NameId, iTerm ); - // remember box - Vec_IntPush( vBoxes, iObj ); - } - // add fanins for box inputs - Psr_NtkForEachBox( pNtk, vSigs, iBox ) - if ( !Psr_BoxIsNode(pNtk, iBox) ) - { - pNtkBox = Psr_ManNtk( vDes, Psr_BoxNtk(pNtk, iBox)-1 ); - iObj = Vec_IntEntry( vBoxes, iBox ); - if ( pNtkBox == NULL ) - { - Vec_IntForEachEntryStop( vSigs, Index, i, Vec_IntSize(vSigs)-2 ) - { - i++; - NameId = Vec_IntEntry( vSigs, i ); - NameId = Psr_NtkSigName( pNtk, NameId ); - iTerm = Bac_BoxBi( pNew, iObj, i/2 ); - if ( Vec_IntEntry(vMap, NameId) == -1 ) - { - iConst0 = Bac_BoxAlloc( pNew, BAC_BOX_CF, 0, 1, -1 ); - Vec_IntWriteEntry( vMap, NameId, iConst0+1 ); - if ( iNonDriven == -1 ) - iNonDriven = NameId; - nNonDriven++; - } - Bac_ObjSetFanin( pNew, iTerm, Vec_IntEntry(vMap, NameId) ); - } - } - else - { - Vec_IntForEachEntry( vSigs, Index, i ) - { - i++; - if ( --Index >= Psr_NtkPiNum(pNtkBox) ) - continue; - NameId = Vec_IntEntry( vSigs, i ); - NameId = Psr_NtkSigName( pNtk, NameId ); - iTerm = Bac_BoxBi( pNew, iObj, Index ); - if ( Vec_IntEntry(vMap, NameId) == -1 ) - { - iConst0 = Bac_BoxAlloc( pNew, BAC_BOX_CF, 0, 1, -1 ); - Vec_IntWriteEntry( vMap, NameId, iConst0+1 ); - if ( iNonDriven == -1 ) - iNonDriven = NameId; - nNonDriven++; - } - Bac_ObjSetFanin( pNew, iTerm, Vec_IntEntry(vMap, NameId) ); - } - } - } - else - { - iObj = Vec_IntEntry( vBoxes, iBox ); - Vec_IntForEachEntryStop( vSigs, Index, i, Vec_IntSize(vSigs)-2 ) - { - NameId = Vec_IntEntry( vSigs, ++i ); - NameId = Psr_NtkSigName( pNtk, NameId ); - iTerm = Bac_BoxBi( pNew, iObj, i/2 ); - if ( Vec_IntEntry(vMap, NameId) == -1 ) - { - iConst0 = Bac_BoxAlloc( pNew, BAC_BOX_CF, 0, 1, -1 ); - Vec_IntWriteEntry( vMap, NameId, iConst0+1 ); - if ( iNonDriven == -1 ) - iNonDriven = NameId; - nNonDriven++; - } - Bac_ObjSetFanin( pNew, iTerm, Vec_IntEntry(vMap, NameId) ); - } - } - // add fanins for primary outputs - Psr_NtkForEachPo( pNtk, NameId, i ) - if ( Vec_IntEntry(vMap, NameId) == -1 ) - { - iConst0 = Bac_BoxAlloc( pNew, BAC_BOX_CF, 0, 1, -1 ); - Vec_IntWriteEntry( vMap, NameId, iConst0+1 ); - if ( iNonDriven == -1 ) - iNonDriven = NameId; - nNonDriven++; - } - Psr_NtkForEachPo( pNtk, NameId, i ) - iObj = Bac_ObjAlloc( pNew, BAC_OBJ_PO, Vec_IntEntry(vMap, NameId) ); - if ( nNonDriven ) - printf( "Module %s has %d non-driven nets (for example, %s).\n", Psr_NtkName(pNtk), nNonDriven, Psr_NtkStr(pNtk, iNonDriven) ); - Psr_ManCleanMap( pNtk, vMap ); - // setup info - Vec_IntForEachEntry( &pNtk->vOrder, NameId, i ) - Bac_NtkAddInfo( pNew, NameId, -1, -1 ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Bac_Man_t * Psr_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes ) -{ - Psr_Ntk_t * pNtk = Psr_ManRoot( vDes ); int i; - Bac_Man_t * pNew = Bac_ManAlloc( pFileName, Vec_PtrSize(vDes) ); - Vec_Int_t * vMap = Vec_IntStartFull( Abc_NamObjNumMax(pNtk->pStrs) + 1 ); - Vec_Int_t * vTmp = Vec_IntAlloc( Psr_NtkBoxNum(pNtk) ); - Abc_NamDeref( pNew->pStrs ); - pNew->pStrs = Abc_NamRef( pNtk->pStrs ); - Vec_PtrForEachEntry( Psr_Ntk_t *, vDes, pNtk, i ) - Bac_NtkAlloc( Bac_ManNtk(pNew, i+1), Psr_NtkId(pNtk), Psr_NtkPiNum(pNtk), Psr_NtkPoNum(pNtk), Psr_NtkCountObjects(pNtk) ); - if ( (pNtk->fMapped || (pNtk->fSlices && Psr_ManIsMapped(pNtk))) && !Bac_NtkBuildLibrary(pNew) ) - Bac_ManFree(pNew), pNew = NULL; - else - Vec_PtrForEachEntry( Psr_Ntk_t *, vDes, pNtk, i ) - Psr_ManBuildNtk( Bac_ManNtk(pNew, i+1), vDes, pNtk, vMap, vTmp ); - assert( Vec_IntCountEntry(vMap, -1) == Vec_IntSize(vMap) ); - Vec_IntFree( vMap ); - Vec_IntFree( vTmp ); -// Vec_StrPrint( &Bac_ManNtk(pNew, 1)->vType, 1 ); - return pNew; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacPrsTrans.c b/src/base/bac/bacPrsTrans.c deleted file mode 100644 index 0aba33710..000000000 --- a/src/base/bac/bacPrsTrans.c +++ /dev/null @@ -1,211 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacPrsTrans.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Parse tree to netlist transformation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacPrsTrans.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Bac_Trip_t_ Bac_Trip_t; -struct Bac_Trip_t_ -{ - Bac_ObjType_t Type; - char * pName; - char * pCode; - char * pSigs[6]; -}; -/* -static Bac_Trip_t s_Types[100] = -{ - { BAC_BOX_CT , "VERIFIC_PWR", "1", {"o"} }, - { BAC_BOX_CF , "VERIFIC_GND", "1", {"o"} }, - { BAC_BOX_CX , "VERIFIC_X", "1", {"o"} }, - { BAC_BOX_CZ , "VERIFIC_Z", "1", {"o"} }, - { BAC_BOX_INV , "VERIFIC_INV", "11", {"i","o"} }, - { BAC_BOX_BUF , "VERIFIC_BUF", "11", {"i","o"} }, - { BAC_BOX_AND , "VERIFIC_AND", "111", {"a0","a1","o"} }, - { BAC_BOX_NAND , "VERIFIC_NAND", "111", {"a0","a1","o"} }, - { BAC_BOX_OR , "VERIFIC_OR", "111", {"a0","a1","o"} }, - { BAC_BOX_NOR , "VERIFIC_NOR", "111", {"a0","a1","o"} }, - { BAC_BOX_XOR , "VERIFIC_XOR", "111", {"a0","a1","o"} }, - { BAC_BOX_XNOR , "VERIFIC_XNOR", "111", {"a0","a1","o"} }, - { BAC_BOX_MUX , "VERIFIC_MUX", "1111", {"c","a1","a0","o"} }, // changed order - { (Bac_ObjType_t)-1, "VERIFIC_PULLUP", "1", {"o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_PULLDOWN", "1", {"o"} }, - { BAC_BOX_TRI , "VERIFIC_TRI", "111", {"i","c","o"} }, - { BAC_BOX_LATCH , "VERIFIC_DLATCH", "11111", {"d","async_val","async_cond","gate","q"} }, // changed order - { BAC_BOX_LATCHRS , "VERIFIC_DLATCHRS", "11111", {"d","s","r","gate","q"} }, // changed order - { BAC_BOX_DFF , "VERIFIC_DFF", "11111", {"d","async_val","async_cond","clk","q"} }, // changed order - { BAC_BOX_DFFRS , "VERIFIC_DFFRS", "11111", {"d","s","r","clk","q"} }, // changed order - { (Bac_ObjType_t)-1, "VERIFIC_NMOS", "111", {"c","d","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_PMOS", "111", {"c","d","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_CMOS", "1111", {"d","nc","pc","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_TRAN", "111", {"inout1","inout2","control"} }, - { BAC_BOX_ADD , "VERIFIC_FADD", "11111", {"cin","a","b","o","cout"} }, - { (Bac_ObjType_t)-1, "VERIFIC_RCMOS", "1111", {"d","nc","pc","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_RNMOS", "111", {"c","d","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_RPMOS", "111", {"c","d","o"} }, - { (Bac_ObjType_t)-1, "VERIFIC_RTRAN", "111", {"inout1","inout2","control"} }, - { (Bac_ObjType_t)-1, "VERIFIC_HDL_ASSERTION", "1", {"condition"} }, - { BAC_BOX_ADD , "add_", "1aba1", {"cin","a","b","o","cout"} }, - { BAC_BOX_MUL , "mult_", "ab?", {"a","b","o"} }, // ? = a * b - { BAC_BOX_DIV , "div_", "ab?", {"a","b","o"} }, // ? = - { BAC_BOX_MOD , "mod_", "ab?", {"a","b","o"} }, // ? = - { BAC_BOX_REM , "rem_", "ab?", {"a","b","o"} }, // ? = - { BAC_BOX_SHIL , "shift_left_", "1aba", {"cin","a","amount","o"} }, - { BAC_BOX_SHIR , "shift_right_", "1aba", {"cin","a","amount","o"} }, - { BAC_BOX_ROTL , "rotate_left_", "aba", {"a","amount","o"} }, - { BAC_BOX_ROTR , "rotate_right_", "aba", {"a","amount","o"} }, - { BAC_BOX_RAND , "reduce_and_", "ab1", {"a","o"} }, - { BAC_BOX_ROR , "reduce_or_", "ab1", {"a","o"} }, - { BAC_BOX_RXOR , "reduce_xor_", "ab1", {"a","o"} }, - { BAC_BOX_RNAND , "reduce_nand_", "ab1", {"a","o"} }, - { BAC_BOX_RNOR , "reduce_nor_", "ab1", {"a","o"} }, - { BAC_BOX_RXNOR , "reduce_xnor_", "ab1", {"a","o"} }, - { BAC_BOX_LTHAN , "LessThan_", "1ab1", {"cin","a","b","o"} }, - { BAC_BOX_NMUX , "Mux_", "ab1", {"sel","data","o"} }, - { BAC_BOX_SEL , "Select_", "aaa", {"sel","data","o"} }, - { BAC_BOX_DEC , "Decoder_", "a?", {"a","o"} }, // ? = (1 << a) - { BAC_BOX_EDEC , "EnabledDecoder_", "1a?", {"en","i","o"} }, // ? = (1 << a) - { BAC_BOX_PSEL , "PrioSelect_", "1aaa", {"cin","sel","data","o"} }, - { BAC_BOX_RAM , "DualPortRam_", "1abab", {"write_enable","write_address","write_data","read_address","read_data"} }, - { BAC_BOX_RAMR , "ReadPort_", "1a1b", {"read_enable", "read_address", "RAM", "read_data" } }, - { BAC_BOX_RAMW , "WritePort_", "1ab1", {"write_enable","write_address","write_data", "RAM"} }, - { BAC_BOX_RAMWC , "ClockedWritePort_", "11ab1", {"clk","write_enable","write_address","write_data", "RAM"} }, - { BAC_BOX_LUT , "lut", "?", {"i","o"} }, - { BAC_BOX_AND , "and_", "aaa", {"a","b","o"} }, - { BAC_BOX_OR , "or_", "aaa", {"a","b","o"} }, - { BAC_BOX_XOR , "xor_", "aaa", {"a","b","o"} }, - { BAC_BOX_NAND , "nand_", "aaa", {"a","b","o"} }, - { BAC_BOX_NOR , "nor_", "aaa", {"a","b","o"} }, - { BAC_BOX_XNOR , "xnor_", "aaa", {"a","b","o"} }, - { BAC_BOX_BUF , "buf_", "aa", {"i","o"} }, - { BAC_BOX_INV , "inv_", "aa", {"i","o"} }, - { BAC_BOX_TRI , "tri_", "a1a", {"i","c","o"} }, - { BAC_BOX_SUB , "sub_", "aaa", {"a","b","o"} }, - { BAC_BOX_MIN , "unary_minus_", "aa", {"i","o"} }, - { BAC_BOX_EQU , "equal_", "aa1", {"a","b","o"} }, - { BAC_BOX_NEQU , "not_equal_", "aa1", {"a","b","o"} }, - { BAC_BOX_MUX , "mux_", "1aaa", {"cond","d1","d0","o"} }, // changed order - { BAC_BOX_NMUX , "wide_mux_", "ab?", {"sel","data","o"} }, // ? = b / (1 << a) - { BAC_BOX_SEL , "wide_select_", "ab?", {"sel","data","o"} }, // ? = b / a - { BAC_BOX_DFF , "wide_dff_", "aaa1a", {"d","async_val","async_cond","clock","q"} }, - { BAC_BOX_DFFRS , "wide_dlatch_", "aaa1a", {"d","set","reset","clock","q"} }, - { BAC_BOX_LATCHRS , "wide_dffrs_", "aaa1a", {"d","set","reset","clock","q"} }, - { BAC_BOX_LATCH , "wide_dlatchrs_", "aaa1a", {"d","async_val","async_cond","clock","q"} }, - { BAC_BOX_PSEL , "wide_prio_select_", "ab??", {"sel","data","carry_in","o"} }, // ? = b / a - { BAC_BOX_POW , "pow_", "abc", {"a","b","o"} }, // ? = - { BAC_BOX_PENC , "PrioEncoder_", "a?", {"sel","o"} }, - { BAC_BOX_ABS , "abs", "aa", {"i","o"} } -}; -*/ - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Count range size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_ManRangeSizeName( Psr_Ntk_t * p, int Name ) -{ - return 1; -} -static inline int Psr_ManRangeSizeRange( Psr_Ntk_t * p, int Range ) -{ - char * pStr; - int Left, Right; - if ( Range == 0 ) - return 1; - pStr = Psr_NtkStr( p, Range ); - assert( pStr[0] == '[' ); - Left = Right = atoi( pStr + 1 ); - pStr = strstr( pStr, "=" ); - if ( pStr ) - Right = atoi( pStr + 1 ); - return 1 + (Left > Right ? Left - Right : Right - Left); -} -static inline int Psr_ManRangeSizeConst( Psr_Ntk_t * p, int Const ) -{ - return atoi( Psr_NtkStr(p, Const) ); -} -static inline int Psr_ManRangeSizeConcat( Psr_Ntk_t * p, int Con ) -{ - extern int Psr_ManRangeSizeArray( Psr_Ntk_t * p, Vec_Int_t * vSlices, int Start, int Stop ); - Vec_Int_t * vSigs = Psr_CatSignals(p, Con); - return Psr_ManRangeSizeArray( p, vSigs, 0, Vec_IntSize(vSigs) ); -} -static inline int Psr_ManRangeSizeSignal( Psr_Ntk_t * p, int Sig ) -{ - int Value = Abc_Lit2Var2( Sig ); - Psr_ManType_t Type = (Psr_ManType_t)Abc_Lit2Att2( Sig ); - if ( Type == BAC_PRS_NAME ) - return Psr_ManRangeSizeName( p, Value ); - if ( Type == BAC_PRS_SLICE ) - return Psr_ManRangeSizeRange( p, Psr_SliceRange(p, Value) ); - if ( Type == BAC_PRS_CONST ) - return Psr_ManRangeSizeConst( p, Value ); - if ( Type == BAC_PRS_CONCAT ) - return Psr_ManRangeSizeConcat( p, Value ); - assert( 0 ); - return 0; -} -int Psr_ManRangeSizeArray( Psr_Ntk_t * p, Vec_Int_t * vSlices, int Start, int Stop ) -{ - int i, Sig, Count = 0; - assert( Vec_IntSize(vSlices) > 0 ); - Vec_IntForEachEntryStartStop( vSlices, Sig, i, Start, Stop ) - Count += Psr_ManRangeSizeSignal( p, Sig ); - return Count; -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacPtr.c b/src/base/bac/bacPtr.c deleted file mode 100644 index c3fc5fd8e..000000000 --- a/src/base/bac/bacPtr.c +++ /dev/null @@ -1,470 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacPtr.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Simple interface with external tools.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacPtr.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "base/abc/abc.h" -#include "base/main/mainInt.h" -#include "map/mio/mio.h" -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/* -design = array containing design name (as the first entry in the array) followed by pointers to modules -module = array containing module name (as the first entry in the array) followed by pointers to 6 arrays: - {array of input names; array of output names; array of nodes; array of boxes, - array of floating-point input-arrival times; array of floating-point output-required times} -node = array containing output name, followed by node type, followed by input names -box = array containing model name, instance name, followed by pairs of formal/actual names for each port - - Comments: - - in describing boxes - - input formal/actual name pairs should be listed before output name pairs - - the order of formal names should be the same as the order of inputs/outputs in the module description - - all formal names present in the module description should be listed - - if an input pin is not driven or an output pin has no fanout, the actual pin name is NULL - - word-level formal name "a" is written as bit-level names (a[0]. a[1], etc) ordered LSB to MSB - - the boxes can appear in any order (topological order is not expected) - - in description of nodes and boxes, primitive names should be given as char*-strings ("AndT", "OrT", etc) - - constant 0/1 nets should be driven by constant nodes having primitive names "Const0T" and "Const1T" - - primitive modules should not be written, but the list of primitives and formal names should be provided - - currently only "boxes" are supported (the array of "nodes" should contain no entries) - - arrays of input-arrival/output-required times in the module description are optional -*/ - -// elementary gates -typedef enum { - PTR_GATE_NONE = 0, - PTR_GATE_C0, // Const0T - PTR_GATE_C1, // Const1T - PTR_GATE_BUF, // BufT - PTR_GATE_INV, // InvT - PTR_GATE_AND, // AndT - PTR_GATE_NAND, // NandT - PTR_GATE_OR, // OrT - PTR_GATE_NOR, // NorT - PTR_GATE_XOR, // XorT - PTR_GATE_XNOR, // XnorT - PTR_GATE_UNKNOWN -} Ptr_ObjType_t; - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Free Ptr.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_PtrFreeNtk( Vec_Ptr_t * vNtk ) -{ - Vec_PtrFree( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1) ); - Vec_PtrFree( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2) ); - Vec_VecFree( (Vec_Vec_t *)Vec_PtrEntry(vNtk, 3) ); - Vec_VecFree( (Vec_Vec_t *)Vec_PtrEntry(vNtk, 4) ); - if ( Vec_PtrSize(vNtk) > 5 ) - Vec_FltFree( (Vec_Flt_t *)Vec_PtrEntry(vNtk, 5) ); - if ( Vec_PtrSize(vNtk) > 6 ) - Vec_FltFree( (Vec_Flt_t *)Vec_PtrEntry(vNtk, 6) ); - Vec_PtrFree( vNtk ); -} -void Bac_PtrFree( Vec_Ptr_t * vDes ) -{ - Vec_Ptr_t * vNtk; int i; - if ( !vDes ) return; - Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) - Bac_PtrFreeNtk( vNtk ); - Vec_PtrFree( vDes ); -} - -/**Function************************************************************* - - Synopsis [Count memory used by Ptr.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Bac_PtrMemoryArray( Vec_Ptr_t * vArray ) -{ - return (int)Vec_PtrMemory(vArray); -} -int Bac_PtrMemoryArrayArray( Vec_Ptr_t * vArrayArray ) -{ - Vec_Ptr_t * vArray; int i, nBytes = 0; - Vec_PtrForEachEntry( Vec_Ptr_t *, vArrayArray, vArray, i ) - nBytes += Bac_PtrMemoryArray(vArray); - return nBytes; -} -int Bac_PtrMemoryNtk( Vec_Ptr_t * vNtk ) -{ - int nBytes = (int)Vec_PtrMemory(vNtk); - nBytes += Bac_PtrMemoryArray( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1) ); - nBytes += Bac_PtrMemoryArray( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2) ); - nBytes += Bac_PtrMemoryArrayArray( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3) ); - nBytes += Bac_PtrMemoryArrayArray( (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4) ); - return nBytes; -} -int Bac_PtrMemory( Vec_Ptr_t * vDes ) -{ - Vec_Ptr_t * vNtk; int i, nBytes = (int)Vec_PtrMemory(vDes); - Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) - nBytes += Bac_PtrMemoryNtk(vNtk); - return nBytes; -} - -/**Function************************************************************* - - Synopsis [Dumping Ptr into a BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_PtrDumpSignalsBlif( FILE * pFile, Vec_Ptr_t * vSigs, int fSkipLastComma ) -{ - char * pSig; int i; - Vec_PtrForEachEntry( char *, vSigs, pSig, i ) - fprintf( pFile, " %s", pSig ); -} -void Bac_PtrDumpBoxBlif( FILE * pFile, Vec_Ptr_t * vBox ) -{ - char * pName; int i; - fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", (char *)Vec_PtrEntry(vBox, 0) ); - //fprintf( pFile, " %s", (char *)Vec_PtrEntry(vBox, 1) ); // do not write intance name in BLIF - Vec_PtrForEachEntryStart( char *, vBox, pName, i, 2 ) - fprintf( pFile, " %s=%s", pName, (char *)Vec_PtrEntry(vBox, i+1) ), i++; - fprintf( pFile, "\n" ); -} -void Bac_PtrDumpBoxesBlif( FILE * pFile, Vec_Ptr_t * vBoxes ) -{ - Vec_Ptr_t * vBox; int i; - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - Bac_PtrDumpBoxBlif( pFile, vBox ); -} -void Bac_PtrDumpModuleBlif( FILE * pFile, Vec_Ptr_t * vNtk ) -{ - fprintf( pFile, ".model %s\n", (char *)Vec_PtrEntry(vNtk, 0) ); - fprintf( pFile, ".inputs" ); - Bac_PtrDumpSignalsBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), 0 ); - fprintf( pFile, "\n" ); - fprintf( pFile, ".outputs" ); - Bac_PtrDumpSignalsBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), 1 ); - fprintf( pFile, "\n" ); - assert( Vec_PtrSize((Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3)) == 0 ); // no nodes; only boxes - Bac_PtrDumpBoxesBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4) ); - fprintf( pFile, ".end\n\n" ); -} -void Bac_PtrDumpBlif( char * pFileName, Vec_Ptr_t * vDes ) -{ - FILE * pFile; - Vec_Ptr_t * vNtk; int i; - pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "// Design \"%s\" written via Ptr in ABC on %s\n\n", (char *)Vec_PtrEntry(vDes, 0), Extra_TimeStamp() ); - Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) - Bac_PtrDumpModuleBlif( pFile, vNtk ); - fclose( pFile ); -} - -/**Function************************************************************* - - Synopsis [Dumping Ptr into a Verilog file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_PtrDumpSignalsVerilog( FILE * pFile, Vec_Ptr_t * vSigs, int fAlwaysComma ) -{ - char * pSig; int i; - Vec_PtrForEachEntry( char *, vSigs, pSig, i ) - fprintf( pFile, " %s%s", pSig, (fAlwaysComma || i < Vec_PtrSize(vSigs) - 1) ? ",":"" ); -} -void Bac_PtrDumpBoxVerilog( FILE * pFile, Vec_Ptr_t * vBox ) -{ - char * pName; int i; - fprintf( pFile, " %s", (char *)Vec_PtrEntry(vBox, 0) ); - fprintf( pFile, " %s (", (char *)Vec_PtrEntry(vBox, 1) ); // write intance name in Verilog - Vec_PtrForEachEntryStart( char *, vBox, pName, i, 2 ) - fprintf( pFile, ".%s(%s)%s", pName, (char *)Vec_PtrEntry(vBox, i+1), i < Vec_PtrSize(vBox) - 2 ? ", ":"" ), i++; - fprintf( pFile, ");\n" ); -} -void Bac_PtrDumpBoxesVerilog( FILE * pFile, Vec_Ptr_t * vBoxes ) -{ - Vec_Ptr_t * vBox; int i; - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - Bac_PtrDumpBoxVerilog( pFile, vBox ); -} -void Bac_PtrDumpModuleVerilog( FILE * pFile, Vec_Ptr_t * vNtk ) -{ - fprintf( pFile, "module %s (\n ", (char *)Vec_PtrEntry(vNtk, 0) ); - Bac_PtrDumpSignalsVerilog( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), 1 ); - Bac_PtrDumpSignalsVerilog( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), 0 ); - fprintf( pFile, "\n );\n" ); - fprintf( pFile, " input" ); - Bac_PtrDumpSignalsVerilog( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), 0 ); - fprintf( pFile, ";\n" ); - fprintf( pFile, " output" ); - Bac_PtrDumpSignalsVerilog( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), 0 ); - fprintf( pFile, ";\n" ); - assert( Vec_PtrSize((Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3)) == 0 ); // no nodes; only boxes - Bac_PtrDumpBoxesVerilog( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4) ); - fprintf( pFile, "endmodule\n\n" ); -} -void Bac_PtrDumpVerilog( char * pFileName, Vec_Ptr_t * vDes ) -{ - FILE * pFile; - Vec_Ptr_t * vNtk; int i; - pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "// Design \"%s\" written via Ptr in ABC on %s\n\n", (char *)Vec_PtrEntry(vDes, 0), Extra_TimeStamp() ); - Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) - Bac_PtrDumpModuleVerilog( pFile, vNtk ); - fclose( pFile ); -} - - -/**Function************************************************************* - - Synopsis [Collect elementary gates from the library.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_ManCollectGateNameOne( Mio_Library_t * pLib, Ptr_ObjType_t Type, word Truth, Vec_Ptr_t * vGateNames ) -{ - Mio_Gate_t * pGate = Mio_LibraryReadGateByTruth( pLib, Truth ); - if ( pGate != NULL ) - Vec_PtrWriteEntry( vGateNames, Type, Mio_GateReadName(pGate) ); -} -Vec_Ptr_t * Bac_ManCollectGateNamesByTruth( Mio_Library_t * pLib ) -{ - static word uTruths6[3] = { - ABC_CONST(0xAAAAAAAAAAAAAAAA), - ABC_CONST(0xCCCCCCCCCCCCCCCC), - ABC_CONST(0xF0F0F0F0F0F0F0F0), - }; - Vec_Ptr_t * vGateNames = Vec_PtrStart( PTR_GATE_UNKNOWN ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_C0, 0, vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_C1, ~(word)0, vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_BUF, uTruths6[0], vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_INV, ~uTruths6[0], vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_AND, (uTruths6[0] & uTruths6[1]), vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_NAND, ~(uTruths6[0] & uTruths6[1]), vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_OR, (uTruths6[0] | uTruths6[1]), vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_NOR, ~(uTruths6[0] | uTruths6[1]), vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_XOR, (uTruths6[0] ^ uTruths6[1]), vGateNames ); - Bac_ManCollectGateNameOne( pLib, PTR_GATE_XNOR, ~(uTruths6[0] ^ uTruths6[1]), vGateNames ); - return vGateNames; -} - -/**Function************************************************************* - - Synopsis [This procedure transforms tech-ind Ptr into mapped Ptr.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_PtrUpdateBox( Vec_Ptr_t * vBox, Vec_Ptr_t * vGatesNames ) -{ - Mio_Gate_t * pGate; Mio_Pin_t * pPin; int i = 1; - Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - // update gate name - char * pNameNew, * pName = (char *)Vec_PtrEntry(vBox, 0); - if ( !strcmp(pName, "Const0T") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_C0); - else if ( !strcmp(pName, "Const1T") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_C1); - else if ( !strcmp(pName, "BufT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_BUF); - else if ( !strcmp(pName, "InvT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_INV); - else if ( !strcmp(pName, "AndT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_AND); - else if ( !strcmp(pName, "NandT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_NAND); - else if ( !strcmp(pName, "OrT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_OR); - else if ( !strcmp(pName, "NorT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_NOR); - else if ( !strcmp(pName, "XorT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_XOR); - else if ( !strcmp(pName, "XnorT") ) - pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_XNOR); - else // user hierarchy - return; - ABC_FREE( pName ); - Vec_PtrWriteEntry( vBox, 0, Abc_UtilStrsav(pNameNew) ); - // remove instance name - pName = (char *)Vec_PtrEntry(vBox, 1); - ABC_FREE( pName ); - Vec_PtrWriteEntry( vBox, 1, NULL ); - // update formal input names - pGate = Mio_LibraryReadGateByName( pLib, pNameNew, NULL ); - Mio_GateForEachPin( pGate, pPin ) - { - pName = (char *)Vec_PtrEntry( vBox, 2 * i ); - ABC_FREE( pName ); - pNameNew = Mio_PinReadName(pPin); - Vec_PtrWriteEntry( vBox, 2 * i++, Abc_UtilStrsav(pNameNew) ); - } - // update output name - pName = (char *)Vec_PtrEntry( vBox, 2 * i ); - pNameNew = Mio_GateReadOutName(pGate); - Vec_PtrWriteEntry( vBox, 2 * i++, Abc_UtilStrsav(pNameNew) ); - assert( 2 * i == Vec_PtrSize(vBox) ); -} -Vec_Ptr_t * Bac_PtrTransformSigs( Vec_Ptr_t * vSig ) -{ - char * pName; int i; - Vec_Ptr_t * vNew = Vec_PtrAllocExact( Vec_PtrSize(vSig) ); - Vec_PtrForEachEntry( char *, vSig, pName, i ) - Vec_PtrPush( vNew, Abc_UtilStrsav(pName) ); - return vNew; -} -Vec_Ptr_t * Bac_PtrTransformBox( Vec_Ptr_t * vBox, Vec_Ptr_t * vGatesNames ) -{ - char * pName; int i; - Vec_Ptr_t * vNew = Vec_PtrAllocExact( Vec_PtrSize(vBox) ); - Vec_PtrForEachEntry( char *, vBox, pName, i ) - Vec_PtrPush( vNew, Abc_UtilStrsav(pName) ); - if ( vGatesNames ) - Bac_PtrUpdateBox( vNew, vGatesNames ); - return vNew; -} -Vec_Ptr_t * Bac_PtrTransformBoxes( Vec_Ptr_t * vBoxes, Vec_Ptr_t * vGatesNames ) -{ - Vec_Ptr_t * vBox; int i; - Vec_Ptr_t * vNew = Vec_PtrAllocExact( Vec_PtrSize(vBoxes) ); - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - Vec_PtrPush( vNew, Bac_PtrTransformBox(vBox, vGatesNames) ); - return vNew; -} -Vec_Ptr_t * Bac_PtrTransformNtk( Vec_Ptr_t * vNtk, Vec_Ptr_t * vGatesNames ) -{ - char * pName = (char *)Vec_PtrEntry(vNtk, 0); - Vec_Ptr_t * vInputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1); - Vec_Ptr_t * vOutputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2); - Vec_Ptr_t * vBoxes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4); - Vec_Ptr_t * vNew = Vec_PtrAllocExact( Vec_PtrSize(vNtk) ); - Vec_PtrPush( vNew, Abc_UtilStrsav(pName) ); - Vec_PtrPush( vNew, Bac_PtrTransformSigs(vInputs) ); - Vec_PtrPush( vNew, Bac_PtrTransformSigs(vOutputs) ); - Vec_PtrPush( vNew, Vec_PtrAllocExact(0) ); - Vec_PtrPush( vNew, Bac_PtrTransformBoxes(vBoxes, vGatesNames) ); - return vNew; -} -Vec_Ptr_t * Bac_PtrTransformTest( Vec_Ptr_t * vDes ) -{ - Mio_Library_t * pLib; - Vec_Ptr_t * vGatesNames; - Vec_Ptr_t * vNtk, * vNew; int i; - // dump BLIF before transformation - Bac_PtrDumpBlif( "test1.blif", vDes ); - if ( Abc_FrameGetGlobalFrame() == NULL ) - { - printf( "ABC framework is not started.\n" ); - return NULL; - } - pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - if ( pLib == NULL ) - { - printf( "Standard cell library is not entered.\n" ); - return NULL; - } - vGatesNames = Bac_ManCollectGateNamesByTruth( pLib ); - // transform - vNew = Vec_PtrAllocExact( Vec_PtrSize(vDes) ); - Vec_PtrPush( vNew, Abc_UtilStrsav((char *)Vec_PtrEntry(vDes, 0)) ); - Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) - Vec_PtrPush( vNew, Bac_PtrTransformNtk(vNtk, vGatesNames) ); - // dump BLIF after transformation - Bac_PtrDumpBlif( "test2.blif", vNew ); - Vec_PtrFree( vGatesNames ); - return vNew; -} - -/**Function************************************************************* - - Synopsis [Test the testing procedure.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_PtrTransformTestTest() -{ - char * pFileName = "c/hie/dump/1/netlist_1.v"; - Abc_Ntk_t * pNtk = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), 0 ); - extern Vec_Ptr_t * Ptr_AbcDeriveDes( Abc_Ntk_t * pNtk ); - Vec_Ptr_t * vDes = Ptr_AbcDeriveDes( pNtk ); - Vec_Ptr_t * vNew = Bac_PtrTransformTest( vDes ); - Bac_PtrFree( vDes ); - Bac_PtrFree( vNew ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacPtrAbc.c b/src/base/bac/bacPtrAbc.c deleted file mode 100644 index 2de211496..000000000 --- a/src/base/bac/bacPtrAbc.c +++ /dev/null @@ -1,486 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacPtrAbc.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Simple interface with external tools.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacPtrAbc.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "base/abc/abc.h" -#include "map/mio/mio.h" -#include "base/main/mainInt.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Node type conversions.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ptr_HopToType( Abc_Obj_t * pObj ) -{ - static word uTruth, uTruths6[3] = { - ABC_CONST(0xAAAAAAAAAAAAAAAA), - ABC_CONST(0xCCCCCCCCCCCCCCCC), - ABC_CONST(0xF0F0F0F0F0F0F0F0), - }; - assert( Abc_ObjIsNode(pObj) ); - uTruth = Hop_ManComputeTruth6( (Hop_Man_t *)Abc_ObjNtk(pObj)->pManFunc, (Hop_Obj_t *)pObj->pData, Abc_ObjFaninNum(pObj) ); -/* - if ( uTruth == 0 ) return "BAC_BOX_C0"; - if ( uTruth == ~(word)0 ) return "BAC_BOX_C1"; - if ( uTruth == uTruths6[0] ) return "BAC_BOX_BUF"; - if ( uTruth == ~uTruths6[0] ) return "BAC_BOX_INV"; - if ( uTruth == (uTruths6[0] & uTruths6[1]) ) return "BAC_BOX_AND"; - if ( uTruth ==~(uTruths6[0] & uTruths6[1]) ) return "BAC_BOX_NAND"; - if ( uTruth == (uTruths6[0] | uTruths6[1]) ) return "BAC_BOX_OR"; - if ( uTruth ==~(uTruths6[0] | uTruths6[1]) ) return "BAC_BOX_NOR"; - if ( uTruth == (uTruths6[0] ^ uTruths6[1]) ) return "BAC_BOX_XOR"; - if ( uTruth ==~(uTruths6[0] ^ uTruths6[1]) ) return "BAC_BOX_XNOR"; -*/ - if ( uTruth == 0 ) return "Const0T"; - if ( uTruth == ~(word)0 ) return "Const1T"; - if ( uTruth == uTruths6[0] ) return "BufT"; - if ( uTruth == ~uTruths6[0] ) return "InvT"; - if ( uTruth == (uTruths6[0] & uTruths6[1]) ) return "AndT"; - if ( uTruth ==~(uTruths6[0] & uTruths6[1]) ) return "NandT"; - if ( uTruth == (uTruths6[0] | uTruths6[1]) ) return "OrT"; - if ( uTruth ==~(uTruths6[0] | uTruths6[1]) ) return "NorT"; - if ( uTruth == (uTruths6[0] ^ uTruths6[1]) ) return "XorT"; - if ( uTruth ==~(uTruths6[0] ^ uTruths6[1]) ) return "XnorT"; - assert( 0 ); - return NULL; -} - - -/**Function************************************************************* - - Synopsis [Create Ptr from Abc_Ntk_t.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ptr_AbcObjName( Abc_Obj_t * pObj ) -{ - if ( Abc_ObjIsNet(pObj) || Abc_ObjIsBox(pObj) ) - return Abc_ObjName(pObj); - if ( Abc_ObjIsCi(pObj) || Abc_ObjIsNode(pObj) ) - return Ptr_AbcObjName(Abc_ObjFanout0(pObj)); - if ( Abc_ObjIsCo(pObj) ) - return Ptr_AbcObjName(Abc_ObjFanin0(pObj)); - assert( 0 ); - return NULL; -} -static int Ptr_CheckArray( Vec_Ptr_t * vArray ) -{ - assert( Vec_PtrSize(vArray) == Vec_PtrCap(vArray) ); - return 1; -} -Vec_Ptr_t * Ptr_AbcDeriveNode( Abc_Obj_t * pObj ) -{ - Abc_Obj_t * pFanin; int i; - Vec_Ptr_t * vNode = Vec_PtrAllocExact( 2 + 2 * (1 + Abc_ObjFaninNum(pObj)) ); - assert( Abc_ObjIsNode(pObj) ); - if ( Abc_NtkHasAig(pObj->pNtk) ) - Vec_PtrPush( vNode, Ptr_HopToType(pObj) ); - else if ( Abc_NtkHasSop(pObj->pNtk) ) - Vec_PtrPush( vNode, Ptr_SopToTypeName((char *)pObj->pData) ); - else assert( 0 ); - Vec_PtrPush( vNode, Ptr_AbcObjName(pObj) ); - assert( Abc_ObjFaninNum(pObj) <= 2 ); - Abc_ObjForEachFanin( pObj, pFanin, i ) - { - Vec_PtrPush( vNode, (void*)(i ? "r" : "l") ); - Vec_PtrPush( vNode, Ptr_AbcObjName(pFanin) ); - } - Vec_PtrPush( vNode, (void*)("o") ); - Vec_PtrPush( vNode, Ptr_AbcObjName(pObj) ); - assert( Ptr_CheckArray(vNode) ); - return vNode; -} -Vec_Ptr_t * Ptr_AbcDeriveBox( Abc_Obj_t * pObj ) -{ - Abc_Obj_t * pNext; int i; - Abc_Ntk_t * pNtk = Abc_ObjModel(pObj); - Vec_Ptr_t * vBox = Vec_PtrAllocExact( 2 + 2 * Abc_ObjFaninNum(pObj) + 2 * Abc_ObjFanoutNum(pObj) ); - assert( Abc_ObjIsBox(pObj) ); - Vec_PtrPush( vBox, Abc_NtkName(pNtk) ); - Vec_PtrPush( vBox, Ptr_AbcObjName(pObj) ); - Abc_ObjForEachFanin( pObj, pNext, i ) - { - Vec_PtrPush( vBox, Ptr_AbcObjName(Abc_NtkPi(pNtk, i)) ); - Vec_PtrPush( vBox, Ptr_AbcObjName(pNext) ); - } - Abc_ObjForEachFanout( pObj, pNext, i ) - { - Vec_PtrPush( vBox, Ptr_AbcObjName(Abc_NtkPo(pNtk, i)) ); - Vec_PtrPush( vBox, Ptr_AbcObjName(pNext) ); - } - assert( Ptr_CheckArray(vBox) ); - return vBox; -} -Vec_Ptr_t * Ptr_AbcDeriveBoxes( Abc_Ntk_t * pNtk ) -{ - Abc_Obj_t * pObj; int i; - Vec_Ptr_t * vBoxes = Vec_PtrAllocExact( Abc_NtkBoxNum(pNtk) + Abc_NtkNodeNum(pNtk) ); - Abc_NtkForEachBox( pNtk, pObj, i ) - Vec_PtrPush( vBoxes, Ptr_AbcDeriveBox(pObj) ); - Abc_NtkForEachNode( pNtk, pObj, i ) - Vec_PtrPush( vBoxes, Ptr_AbcDeriveNode(pObj) ); - assert( Ptr_CheckArray(vBoxes) ); - return vBoxes; -} - -Vec_Ptr_t * Ptr_AbcDeriveInputs( Abc_Ntk_t * pNtk ) -{ - Abc_Obj_t * pObj; int i; - Vec_Ptr_t * vSigs = Vec_PtrAllocExact( Abc_NtkPiNum(pNtk) ); - Abc_NtkForEachPi( pNtk, pObj, i ) - Vec_PtrPush( vSigs, Ptr_AbcObjName(pObj) ); - assert( Ptr_CheckArray(vSigs) ); - return vSigs; -} -Vec_Ptr_t * Ptr_AbcDeriveOutputs( Abc_Ntk_t * pNtk ) -{ - Abc_Obj_t * pObj; int i; - Vec_Ptr_t * vSigs = Vec_PtrAllocExact( Abc_NtkPoNum(pNtk) ); - Abc_NtkForEachPo( pNtk, pObj, i ) - Vec_PtrPush( vSigs, Ptr_AbcObjName(pObj) ); - assert( Ptr_CheckArray(vSigs) ); - return vSigs; -} -Vec_Ptr_t * Ptr_AbcDeriveNtk( Abc_Ntk_t * pNtk ) -{ - Vec_Ptr_t * vNtk = Vec_PtrAllocExact( 5 ); - Vec_PtrPush( vNtk, Abc_NtkName(pNtk) ); - Vec_PtrPush( vNtk, Ptr_AbcDeriveInputs(pNtk) ); - Vec_PtrPush( vNtk, Ptr_AbcDeriveOutputs(pNtk) ); - Vec_PtrPush( vNtk, Vec_PtrAllocExact(0) ); - Vec_PtrPush( vNtk, Ptr_AbcDeriveBoxes(pNtk) ); - assert( Ptr_CheckArray(vNtk) ); - return vNtk; -} -Vec_Ptr_t * Ptr_AbcDeriveDes( Abc_Ntk_t * pNtk ) -{ - Vec_Ptr_t * vDes; - Abc_Ntk_t * pTemp; int i; - vDes = Vec_PtrAllocExact( 1 + Vec_PtrSize(pNtk->pDesign->vModules) ); - Vec_PtrPush( vDes, pNtk->pDesign->pName ); - Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pTemp, i ) - Vec_PtrPush( vDes, Ptr_AbcDeriveNtk(pTemp) ); - assert( Ptr_CheckArray(vDes) ); - return vDes; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ptr_ManExperiment( Abc_Ntk_t * pNtk ) -{ - abctime clk = Abc_Clock(); - char * pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out.blif"); - Vec_Ptr_t * vDes = Ptr_AbcDeriveDes( pNtk ); - printf( "Converting to Ptr: Memory = %6.3f MB ", 1.0*Bac_PtrMemory(vDes)/(1<<20) ); - Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); - Bac_PtrDumpBlif( pFileName, vDes ); - printf( "Finished writing output file \"%s\". ", pFileName ); - Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); - Bac_PtrFree( vDes ); -} - -/**Function************************************************************* - - Synopsis [Create Bac_Man_t from tech-ind Ptr.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Ptr_NameToType( char * pSop ) -{ - if ( !strcmp(pSop, "Const0T") ) return BAC_BOX_CF; - if ( !strcmp(pSop, "Const1T") ) return BAC_BOX_CT; - if ( !strcmp(pSop, "BufT") ) return BAC_BOX_BUF; - if ( !strcmp(pSop, "InvT") ) return BAC_BOX_INV; - if ( !strcmp(pSop, "AndT") ) return BAC_BOX_AND; - if ( !strcmp(pSop, "NandT") ) return BAC_BOX_NAND; - if ( !strcmp(pSop, "OrT") ) return BAC_BOX_OR; - if ( !strcmp(pSop, "NorT") ) return BAC_BOX_NOR; - if ( !strcmp(pSop, "XorT") ) return BAC_BOX_XOR; - if ( !strcmp(pSop, "XnorT") ) return BAC_BOX_XNOR; - return BAC_OBJ_BOX; -} -int Ptr_ManCountNtk( Vec_Ptr_t * vNtk ) -{ - Vec_Ptr_t * vInputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1); - Vec_Ptr_t * vOutputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2); - Vec_Ptr_t * vNodes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3); - Vec_Ptr_t * vBoxes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4); - Vec_Ptr_t * vBox; int i, Counter = 0; - assert( Vec_PtrSize(vNodes) == 0 ); - Counter += Vec_PtrSize(vInputs); - Counter += Vec_PtrSize(vOutputs); - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - Counter += Vec_PtrSize(vBox)/2; - return Counter; -} -int Bac_BoxCountOutputs( Bac_Ntk_t * pNtk, char * pBoxNtk ) -{ - int ModuleId = Bac_ManNtkFindId( pNtk->pDesign, pBoxNtk ); - if ( ModuleId == 0 ) - return 1; - return Bac_NtkPoNumAlloc( Bac_ManNtk(pNtk->pDesign, ModuleId) ); -} -int Bac_NtkDeriveFromPtr( Bac_Ntk_t * pNtk, Vec_Ptr_t * vNtk, Vec_Int_t * vMap, Vec_Int_t * vBox2Id ) -{ - char * pName, * pModuleName = (char *)Vec_PtrEntry(vNtk, 0); - Vec_Ptr_t * vInputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1); - Vec_Ptr_t * vOutputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2); - Vec_Ptr_t * vBoxes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4), * vBox; - int i, k, iObj, iTerm, NameId; - // start network with the given name - NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pModuleName, NULL ); - assert( Bac_NtkNameId(pNtk) == NameId ); - // map driven NameIds into their ObjIds for PIs - Vec_PtrForEachEntry( char *, vInputs, pName, i ) - { - NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL ); - if ( Vec_IntGetEntryFull(vMap, NameId) != -1 ) - { printf( "PI with name \"%s\" is not unique module \"%s\".\n", pName, pModuleName ); return 0; } - iObj = Bac_ObjAlloc( pNtk, BAC_OBJ_PI, -1 ); - Bac_ObjSetName( pNtk, iObj, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntSetEntryFull( vMap, NameId, iObj ); - Bac_NtkAddInfo( pNtk, Abc_Var2Lit2(NameId, 1), -1, -1 ); - } - // map driven NameIds into their ObjIds for BOs - Vec_IntClear( vBox2Id ); - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - { - char * pBoxNtk = (char *)Vec_PtrEntry(vBox, 0); - char * pBoxName = (char *)Vec_PtrEntry(vBox, 1); - int nOutputs = Bac_BoxCountOutputs( pNtk, pBoxNtk ); - int nInputs = Vec_PtrSize(vBox)/2 - nOutputs - 1; - int NtkId = Bac_ManNtkFindId( pNtk->pDesign, pBoxNtk ); - assert( Vec_PtrSize(vBox) % 2 == 0 ); - assert( nOutputs > 0 && 2*(nOutputs + 1) <= Vec_PtrSize(vBox) ); - iObj = Bac_BoxAlloc( pNtk, (Bac_ObjType_t)Ptr_NameToType(pBoxNtk), nInputs, nOutputs, NtkId ); - if ( NtkId > 0 ) - Bac_NtkSetHost( Bac_ManNtk(pNtk->pDesign, NtkId), Bac_NtkId(pNtk), iObj ); - Bac_ObjSetName( pNtk, iObj, Abc_Var2Lit2(Abc_NamStrFindOrAdd(pNtk->pDesign->pStrs, pBoxName, NULL), BAC_NAME_BIN) ); - Bac_BoxForEachBo( pNtk, iObj, iTerm, k ) - { - pName = (char *)Vec_PtrEntry( vBox, Vec_PtrSize(vBox) - 2*(nOutputs - k) + 1 ); - NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL ); - if ( Vec_IntGetEntryFull(vMap, NameId) != -1 ) - { printf( "Signal \"%s\" has multiple drivers in module \"%s\".\n", pName, pModuleName ); return 0; } - Bac_ObjSetName( pNtk, iTerm, Abc_Var2Lit2(NameId, BAC_NAME_BIN) ); - Vec_IntSetEntryFull( vMap, NameId, iTerm ); - } - Vec_IntPush( vBox2Id, iObj ); - } - assert( Vec_IntSize(vBox2Id) == Vec_PtrSize(vBoxes) ); - // connect BIs - Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i ) - { - iObj = Vec_IntEntry( vBox2Id, i ); - Bac_BoxForEachBi( pNtk, iObj, iTerm, k ) - { - pName = (char *)Vec_PtrEntry( vBox, 2*(k + 1) + 1 ); - NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL ); - if ( Vec_IntGetEntryFull(vMap, NameId) == -1 ) - printf( "Signal \"%s\" in not driven in module \"%s\".\n", pName, pModuleName ); - Bac_ObjSetFanin( pNtk, iTerm, Vec_IntGetEntryFull(vMap, NameId) ); - } - } - // connect POs - Vec_PtrForEachEntry( char *, vOutputs, pName, i ) - { - NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL ); - if ( Vec_IntGetEntryFull(vMap, NameId) == -1 ) - printf( "PO with name \"%s\" in not driven in module \"%s\".\n", pName, pModuleName ); - iObj = Bac_ObjAlloc( pNtk, BAC_OBJ_PO, Vec_IntGetEntryFull(vMap, NameId) ); - Bac_NtkAddInfo( pNtk, Abc_Var2Lit2(NameId, 2), -1, -1 ); - } - // update map - Bac_NtkForEachCi( pNtk, iObj ) - Vec_IntSetEntryFull( vMap, Bac_ObjNameId(pNtk, iObj), -1 ); - // double check - Vec_IntForEachEntry( vMap, iObj, i ) - assert( iObj == -1 ); - assert( Bac_NtkObjNum(pNtk) == Vec_StrCap(&pNtk->vType) ); - return 1; -} -Bac_Man_t * Bac_PtrTransformToCba( Vec_Ptr_t * vDes ) -{ - char * pName = (char *)Vec_PtrEntry(vDes, 0); - Bac_Man_t * pNew = Bac_ManAlloc( pName, Vec_PtrSize(vDes) - 1 ); - Vec_Int_t * vMap = Vec_IntStartFull( 1000 ); - Vec_Int_t * vBox2Id = Vec_IntAlloc( 1000 ); - // create interfaces - Bac_Ntk_t * pNtk; int i; - Bac_ManForEachNtk( pNew, pNtk, i ) - { - Vec_Ptr_t * vNtk = (Vec_Ptr_t *)Vec_PtrEntry(vDes, i); - Vec_Ptr_t * vInputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1); - Vec_Ptr_t * vOutputs = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2); - int NameId = Abc_NamStrFindOrAdd( pNew->pStrs, (char *)Vec_PtrEntry(vNtk, 0), NULL ); - Bac_NtkAlloc( pNtk, NameId, Vec_PtrSize(vInputs), Vec_PtrSize(vOutputs), Ptr_ManCountNtk(vNtk) ); - Bac_NtkStartNames( pNtk ); - } - // parse the networks - Bac_ManForEachNtk( pNew, pNtk, i ) - { - Vec_Ptr_t * vNtk = (Vec_Ptr_t *)Vec_PtrEntry(vDes, i); - if ( !Bac_NtkDeriveFromPtr( pNtk, vNtk, vMap, vBox2Id ) ) - break; - } - if ( i <= Bac_ManNtkNum(pNew) ) - Bac_ManFree(pNew), pNew = NULL; - Vec_IntFree( vBox2Id ); - Vec_IntFree( vMap ); - return pNew; -} - - -/**Function************************************************************* - - Synopsis [Create Ptr from mapped Bac_Man_t.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Bac_NtkTransformToPtrBox( Bac_Ntk_t * p, int iBox ) -{ - int i, iTerm, fUser = Bac_ObjIsBoxUser( p, iBox ); - Bac_Ntk_t * pBoxNtk = Bac_BoxNtk( p, iBox ); - Mio_Library_t * pLib = (Mio_Library_t *)p->pDesign->pMioLib; - Mio_Gate_t * pGate = pLib ? Mio_LibraryReadGateByName( pLib, Bac_BoxNtkName(p, iBox), NULL ) : NULL; - Vec_Ptr_t * vBox = Vec_PtrAllocExact( 2*Bac_BoxSize(p, iBox) ); - Vec_PtrPush( vBox, Bac_BoxNtkName(p, iBox) ); - Vec_PtrPush( vBox, Bac_ObjNameStr(p, iBox) ); - Bac_BoxForEachBi( p, iBox, iTerm, i ) - { - Vec_PtrPush( vBox, fUser ? Bac_ObjNameStr(pBoxNtk, Bac_NtkPi(pBoxNtk, i)) : Mio_GateReadPinName(pGate, i) ); - Vec_PtrPush( vBox, Bac_ObjNameStr(p, iTerm) ); - } - Bac_BoxForEachBo( p, iBox, iTerm, i ) - { - Vec_PtrPush( vBox, fUser ? Bac_ObjNameStr(pBoxNtk, Bac_NtkPo(pBoxNtk, i)) : Mio_GateReadOutName(pGate) ); - Vec_PtrPush( vBox, Bac_ObjNameStr(p, iTerm) ); - } - assert( Ptr_CheckArray(vBox) ); - return vBox; -} -Vec_Ptr_t * Bac_NtkTransformToPtrBoxes( Bac_Ntk_t * p ) -{ - int iBox; - Vec_Ptr_t * vBoxes = Vec_PtrAllocExact( Bac_NtkBoxNum(p) ); - Bac_NtkForEachBox( p, iBox ) - Vec_PtrPush( vBoxes, Bac_NtkTransformToPtrBox(p, iBox) ); - assert( Ptr_CheckArray(vBoxes) ); - return vBoxes; -} - -Vec_Ptr_t * Bac_NtkTransformToPtrInputs( Bac_Ntk_t * p ) -{ - int i, iTerm; - Vec_Ptr_t * vSigs = Vec_PtrAllocExact( Bac_NtkPiNum(p) ); - Bac_NtkForEachPi( p, iTerm, i ) - Vec_PtrPush( vSigs, Bac_ObjNameStr(p, iTerm) ); - assert( Ptr_CheckArray(vSigs) ); - return vSigs; -} -Vec_Ptr_t * Bac_NtkTransformToPtrOutputs( Bac_Ntk_t * p ) -{ - int i, iTerm; - Vec_Ptr_t * vSigs = Vec_PtrAllocExact( Bac_NtkPoNum(p) ); - Bac_NtkForEachPo( p, iTerm, i ) - Vec_PtrPush( vSigs, Bac_ObjNameStr(p, iTerm) ); - assert( Ptr_CheckArray(vSigs) ); - return vSigs; -} -Vec_Ptr_t * Bac_NtkTransformToPtr( Bac_Ntk_t * p ) -{ - Vec_Ptr_t * vNtk = Vec_PtrAllocExact(5); - Vec_PtrPush( vNtk, Bac_NtkName(p) ); - Vec_PtrPush( vNtk, Bac_NtkTransformToPtrInputs(p) ); - Vec_PtrPush( vNtk, Bac_NtkTransformToPtrOutputs(p) ); - Vec_PtrPush( vNtk, Vec_PtrAllocExact(0) ); - Vec_PtrPush( vNtk, Bac_NtkTransformToPtrBoxes(p) ); - assert( Ptr_CheckArray(vNtk) ); - return vNtk; -} -Vec_Ptr_t * Bac_PtrDeriveFromCba( Bac_Man_t * p ) -{ - Vec_Ptr_t * vDes; - Bac_Ntk_t * pTemp; int i; - if ( p == NULL ) - return NULL; - if ( p->pMioLib == NULL ) - { - printf( "Cannot transform CBA network into Ptr because it is not mapped.\n" ); - return NULL; - } - Bac_ManAssignInternWordNames( p ); - vDes = Vec_PtrAllocExact( 1 + Bac_ManNtkNum(p) ); - Vec_PtrPush( vDes, p->pName ); - Bac_ManForEachNtk( p, pTemp, i ) - Vec_PtrPush( vDes, Bac_NtkTransformToPtr(pTemp) ); - assert( Ptr_CheckArray(vDes) ); - return vDes; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacReadBlif.c b/src/base/bac/bacReadBlif.c deleted file mode 100644 index 4a1839b65..000000000 --- a/src/base/bac/bacReadBlif.c +++ /dev/null @@ -1,453 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacReadBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [BLIF parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacReadBlif.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// BLIF keywords -typedef enum { - PRS_BLIF_NONE = 0, // 0: unused - PRS_BLIF_MODEL, // 1: .model - PRS_BLIF_INOUTS, // 2: .inouts - PRS_BLIF_INPUTS, // 3: .inputs - PRS_BLIF_OUTPUTS, // 4: .outputs - PRS_BLIF_NAMES, // 5: .names - PRS_BLIF_SUBCKT, // 6: .subckt - PRS_BLIF_GATE, // 7: .gate - PRS_BLIF_LATCH, // 8: .latch - PRS_BLIF_SHORT, // 9: .short - PRS_BLIF_END, // 10: .end - PRS_BLIF_UNKNOWN // 11: unknown -} Bac_BlifType_t; - -static const char * s_BlifTypes[PRS_BLIF_UNKNOWN+1] = { - NULL, // 0: unused - ".model", // 1: .model - ".inouts", // 2: .inputs - ".inputs", // 3: .inputs - ".outputs", // 4: .outputs - ".names", // 5: .names - ".subckt", // 6: .subckt - ".gate", // 7: .gate - ".latch", // 8: .latch - ".short", // 9: .short - ".end", // 10: .end - NULL // 11: unknown -}; - -static inline void Psr_NtkAddBlifDirectives( Psr_Man_t * p ) -{ - int i; - for ( i = 1; s_BlifTypes[i]; i++ ) - Abc_NamStrFindOrAdd( p->pStrs, (char *)s_BlifTypes[i], NULL ); - assert( Abc_NamObjNumMax(p->pStrs) == i ); -} - - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Reading characters.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_CharIsSpace( char c ) { return c == ' ' || c == '\t' || c == '\r'; } -static inline int Psr_CharIsStop( char c ) { return c == '#' || c == '\\' || c == '\n' || c == '='; } -static inline int Psr_CharIsLit( char c ) { return c == '0' || c == '1' || c == '-'; } - -static inline int Psr_ManIsSpace( Psr_Man_t * p ) { return Psr_CharIsSpace(*p->pCur); } -static inline int Psr_ManIsStop( Psr_Man_t * p ) { return Psr_CharIsStop(*p->pCur); } -static inline int Psr_ManIsLit( Psr_Man_t * p ) { return Psr_CharIsLit(*p->pCur); } - -static inline int Psr_ManIsChar( Psr_Man_t * p, char c ) { return *p->pCur == c; } -static inline int Psr_ManIsChar2( Psr_Man_t * p, char c ) { return *p->pCur++ == c; } - -static inline void Psr_ManSkip( Psr_Man_t * p ) { p->pCur++; } -static inline char Psr_ManSkip2( Psr_Man_t * p ) { return *p->pCur++; } - - -/**Function************************************************************* - - Synopsis [Reading names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Psr_ManSkipToChar( Psr_Man_t * p, char c ) -{ - while ( !Psr_ManIsChar(p, c) ) - Psr_ManSkip(p); -} -static inline void Psr_ManSkipSpaces( Psr_Man_t * p ) -{ - while ( 1 ) - { - while ( Psr_ManIsSpace(p) ) - Psr_ManSkip(p); - if ( Psr_ManIsChar(p, '\\') ) - { - Psr_ManSkipToChar( p, '\n' ); - Psr_ManSkip(p); - continue; - } - if ( Psr_ManIsChar(p, '#') ) - Psr_ManSkipToChar( p, '\n' ); - break; - } - assert( !Psr_ManIsSpace(p) ); -} -static inline int Psr_ManReadName( Psr_Man_t * p ) -{ - char * pStart; - Psr_ManSkipSpaces( p ); - if ( Psr_ManIsChar(p, '\n') ) - return 0; - pStart = p->pCur; - while ( !Psr_ManIsSpace(p) && !Psr_ManIsStop(p) ) - Psr_ManSkip(p); - if ( pStart == p->pCur ) - return 0; - return Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur, NULL ); -} -static inline int Psr_ManReadList( Psr_Man_t * p, Vec_Int_t * vOrder, int Type ) -{ - int iToken; - Vec_IntClear( &p->vTemp ); - while ( (iToken = Psr_ManReadName(p)) ) - { - Vec_IntPush( &p->vTemp, iToken ); - Vec_IntPush( vOrder, Abc_Var2Lit2(iToken, Type) ); - } - if ( Vec_IntSize(&p->vTemp) == 0 ) return Psr_ManErrorSet(p, "Signal list is empty.", 1); - return 0; -} -static inline int Psr_ManReadList2( Psr_Man_t * p ) -{ - int iToken; - Vec_IntClear( &p->vTemp ); - while ( (iToken = Psr_ManReadName(p)) ) - Vec_IntPushTwo( &p->vTemp, 0, iToken ); - if ( Vec_IntSize(&p->vTemp) == 0 ) return Psr_ManErrorSet(p, "Signal list is empty.", 1); - return 0; -} -static inline int Psr_ManReadList3( Psr_Man_t * p ) -{ - Vec_IntClear( &p->vTemp ); - while ( !Psr_ManIsChar(p, '\n') ) - { - int iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read formal name.", 1); - Vec_IntPush( &p->vTemp, iToken ); - Psr_ManSkipSpaces( p ); - if ( !Psr_ManIsChar2(p, '=') ) return Psr_ManErrorSet(p, "Cannot find symbol \"=\".", 1); - iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read actual name.", 1); - Vec_IntPush( &p->vTemp, iToken ); - Psr_ManSkipSpaces( p ); - } - if ( Vec_IntSize(&p->vTemp) == 0 ) return Psr_ManErrorSet(p, "Cannot read a list of formal/actual names.", 1); - if ( Vec_IntSize(&p->vTemp) % 2 ) return Psr_ManErrorSet(p, "The number of formal/actual names is not even.", 1); - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_ManReadCube( Psr_Man_t * p ) -{ - assert( Psr_ManIsLit(p) ); - while ( Psr_ManIsLit(p) ) - Vec_StrPush( &p->vCover, Psr_ManSkip2(p) ); - Psr_ManSkipSpaces( p ); - if ( Psr_ManIsChar(p, '\n') ) - { - if ( Vec_StrSize(&p->vCover) != 1 ) return Psr_ManErrorSet(p, "Cannot read cube.", 1); - // fix single literal cube by adding space - Vec_StrPush( &p->vCover, Vec_StrEntry(&p->vCover,0) ); - Vec_StrWriteEntry( &p->vCover, 0, ' ' ); - Vec_StrPush( &p->vCover, '\n' ); - return 0; - } - if ( !Psr_ManIsLit(p) ) return Psr_ManErrorSet(p, "Cannot read output literal.", 1); - Vec_StrPush( &p->vCover, ' ' ); - Vec_StrPush( &p->vCover, Psr_ManSkip2(p) ); - Vec_StrPush( &p->vCover, '\n' ); - Psr_ManSkipSpaces( p ); - if ( !Psr_ManIsChar(p, '\n') ) return Psr_ManErrorSet(p, "Cannot read end of cube.", 1); - return 0; -} -static inline void Psr_ManSaveCover( Psr_Man_t * p ) -{ - int iToken; - if ( Vec_StrSize(&p->vCover) == 0 ) - p->pNtk->fHasC0s = 1; - else if ( Vec_StrSize(&p->vCover) == 2 ) - { - if ( Vec_StrEntryLast(&p->vCover) == '0' ) - p->pNtk->fHasC0s = 1; - else if ( Vec_StrEntryLast(&p->vCover) == '1' ) - p->pNtk->fHasC1s = 1; - else assert( 0 ); - } - 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) ); - Vec_StrClear( &p->vCover ); - // set the cover to the module of this box - assert( Psr_BoxNtk(p->pNtk, Psr_NtkBoxNum(p->pNtk)-1) == 1 ); // default const 0 - Psr_BoxSetNtk( p->pNtk, Psr_NtkBoxNum(p->pNtk)-1, iToken ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_ManReadInouts( Psr_Man_t * p ) -{ - if ( Psr_ManReadList(p, &p->pNtk->vOrder, 3) ) return 1; - Vec_IntAppend( &p->pNtk->vInouts, &p->vTemp ); - return 0; -} -static inline int Psr_ManReadInputs( Psr_Man_t * p ) -{ - if ( Psr_ManReadList(p, &p->pNtk->vOrder, 1) ) return 1; - Vec_IntAppend( &p->pNtk->vInputs, &p->vTemp ); - return 0; -} -static inline int Psr_ManReadOutputs( Psr_Man_t * p ) -{ - if ( Psr_ManReadList(p, &p->pNtk->vOrder, 2) ) return 1; - Vec_IntAppend( &p->pNtk->vOutputs, &p->vTemp ); - return 0; -} -static inline int Psr_ManReadNode( Psr_Man_t * p ) -{ - if ( Psr_ManReadList2(p) ) return 1; - // save results - Psr_NtkAddBox( p->pNtk, 1, 0, &p->vTemp ); // default const 0 function - return 0; -} -static inline int Psr_ManReadBox( Psr_Man_t * p, int fGate ) -{ - int iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read model name.", 1); - if ( Psr_ManReadList3(p) ) return 1; - // save results - Psr_NtkAddBox( p->pNtk, iToken, 0, &p->vTemp ); - if ( fGate ) p->pNtk->fMapped = 1; - return 0; -} -static inline int Psr_ManReadLatch( Psr_Man_t * p ) -{ - int iToken = Psr_ManReadName(p); - Vec_IntClear( &p->vTemp ); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read latch input.", 1); - Vec_IntWriteEntry( &p->vTemp, 1, iToken ); - iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read latch output.", 1); - Vec_IntWriteEntry( &p->vTemp, 0, iToken ); - Psr_ManSkipSpaces( p ); - if ( Psr_ManIsChar(p, '0') ) - iToken = 0; - else if ( Psr_ManIsChar(p, '1') ) - iToken = 1; - else - iToken = 2; - Psr_ManSkipToChar( p, '\n' ); - // save results - Psr_NtkAddBox( p->pNtk, -1, iToken, &p->vTemp ); // -1 stands for latch - return 0; -} -static inline int Psr_ManReadShort( Psr_Man_t * p ) -{ - int iToken = Psr_ManReadName(p); - Vec_IntClear( &p->vTemp ); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read .short input.", 1); - Vec_IntWriteEntry( &p->vTemp, 1, iToken ); - iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read .short output.", 1); - Vec_IntWriteEntry( &p->vTemp, 0, iToken ); - Psr_ManSkipSpaces( p ); - if ( !Psr_ManIsChar(p, '\n') ) return Psr_ManErrorSet(p, "Trailing symbols on .short line.", 1); - // save results - iToken = Abc_NamStrFindOrAdd( p->pStrs, "1 1\n", NULL ); - Psr_NtkAddBox( p->pNtk, iToken, 0, &p->vTemp ); - return 0; -} -static inline int Psr_ManReadModel( Psr_Man_t * p ) -{ - int iToken; - if ( p->pNtk != NULL ) return Psr_ManErrorSet(p, "Parsing previous model is unfinished.", 1); - iToken = Psr_ManReadName(p); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read model name.", 1); - Psr_ManInitializeNtk( p, iToken, 0 ); - Psr_ManSkipSpaces( p ); - if ( !Psr_ManIsChar(p, '\n') ) return Psr_ManErrorSet(p, "Trailing symbols on .model line.", 1); - return 0; -} -static inline int Psr_ManReadEnd( Psr_Man_t * p ) -{ - if ( p->pNtk == 0 ) return Psr_ManErrorSet(p, "Directive .end without .model.", 1); - //printf( "Saving model \"%s\".\n", Abc_NamStr(p->pStrs, p->iModuleName) ); - Psr_ManFinalizeNtk( p ); - Psr_ManSkipSpaces( p ); - if ( !Psr_ManIsChar(p, '\n') ) return Psr_ManErrorSet(p, "Trailing symbols on .end line.", 1); - return 0; -} - -static inline int Psr_ManReadDirective( Psr_Man_t * p ) -{ - int iToken; - if ( !Psr_ManIsChar(p, '.') ) - return Psr_ManReadCube( p ); - if ( Vec_StrSize(&p->vCover) > 0 ) // SOP was specified for the previous node - Psr_ManSaveCover( p ); - iToken = Psr_ManReadName( p ); - if ( iToken == PRS_BLIF_MODEL ) - return Psr_ManReadModel( p ); - if ( iToken == PRS_BLIF_INOUTS ) - return Psr_ManReadInouts( p ); - if ( iToken == PRS_BLIF_INPUTS ) - return Psr_ManReadInputs( p ); - if ( iToken == PRS_BLIF_OUTPUTS ) - return Psr_ManReadOutputs( p ); - if ( iToken == PRS_BLIF_NAMES ) - return Psr_ManReadNode( p ); - if ( iToken == PRS_BLIF_SUBCKT ) - return Psr_ManReadBox( p, 0 ); - if ( iToken == PRS_BLIF_GATE ) - return Psr_ManReadBox( p, 1 ); - if ( iToken == PRS_BLIF_LATCH ) - return Psr_ManReadLatch( p ); - if ( iToken == PRS_BLIF_SHORT ) - return Psr_ManReadShort( p ); - if ( iToken == PRS_BLIF_END ) - return Psr_ManReadEnd( p ); - printf( "Cannot read directive \"%s\".\n", Abc_NamStr(p->pStrs, iToken) ); - return 1; -} -static inline int Psr_ManReadLines( Psr_Man_t * p ) -{ - while ( p->pCur[1] != '\0' ) - { - assert( Psr_ManIsChar(p, '\n') ); - Psr_ManSkip(p); - Psr_ManSkipSpaces( p ); - if ( Psr_ManIsChar(p, '\n') ) - continue; - if ( Psr_ManReadDirective(p) ) - return 1; - } - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Psr_ManReadBlif( char * pFileName ) -{ - Vec_Ptr_t * vPrs = NULL; - Psr_Man_t * p = Psr_ManAlloc( pFileName ); - if ( p == NULL ) - return NULL; - Psr_NtkAddBlifDirectives( p ); - Psr_ManReadLines( p ); - if ( Psr_ManErrorPrint(p) ) - ABC_SWAP( Vec_Ptr_t *, vPrs, p->vNtks ); - Psr_ManFree( p ); - return vPrs; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Psr_ManReadBlifTest() -{ - abctime clk = Abc_Clock(); - extern void Psr_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ); -// Vec_Ptr_t * vPrs = Psr_ManReadBlif( "aga/ray/ray_hie_oper.blif" ); - Vec_Ptr_t * vPrs = Psr_ManReadBlif( "c/hie/dump/1/netlist_1_out8.blif" ); - if ( !vPrs ) return; - printf( "Finished reading %d networks. ", Vec_PtrSize(vPrs) ); - printf( "NameIDs = %d. ", Abc_NamObjNumMax(Psr_ManNameMan(vPrs)) ); - printf( "Memory = %.2f MB. ", 1.0*Psr_ManMemory(vPrs)/(1<<20) ); - Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); -// Abc_NamPrint( p->pStrs ); - Psr_ManWriteBlif( "c/hie/dump/1/netlist_1_out8_out.blif", vPrs ); - Psr_ManVecFree( vPrs ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacReadSmt.c b/src/base/bac/bacReadSmt.c deleted file mode 100644 index 56fdaaea4..000000000 --- a/src/base/bac/bacReadSmt.c +++ /dev/null @@ -1,42 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacReadSmt.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [BLIF parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacReadSmt.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacReadVer.c b/src/base/bac/bacReadVer.c deleted file mode 100644 index eb5c42702..000000000 --- a/src/base/bac/bacReadVer.c +++ /dev/null @@ -1,875 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacReadVer.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [BLIF writer.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacReadVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// Verilog keywords -typedef enum { - PRS_VER_NONE = 0, // 0: unused - PRS_VER_INPUT, // 1: input - PRS_VER_OUTPUT, // 2: output - PRS_VER_INOUT, // 3: inout - PRS_VER_WIRE, // 4: wire - PRS_VER_MODULE, // 5: module - PRS_VER_ASSIGN, // 6: assign - PRS_VER_REG, // 7: reg - PRS_VER_ALWAYS, // 8: always - PRS_VER_DEFPARAM, // 9: always - PRS_VER_BEGIN, // 10: begin - PRS_VER_END, // 11: end - PRS_VER_ENDMODULE, // 12: endmodule - PRS_VER_UNKNOWN // 13: unknown -} Bac_VerType_t; - -static const char * s_VerTypes[PRS_VER_UNKNOWN+1] = { - NULL, // 0: unused - "input", // 1: input - "output", // 2: output - "inout", // 3: inout - "wire", // 4: wire - "module", // 5: module - "assign", // 6: assign - "reg", // 7: reg - "always", // 8: always - "defparam", // 9: defparam - "begin", // 10: begin - "end", // 11: end - "endmodule", // 12: endmodule - NULL // 13: unknown -}; - -static inline void Psr_NtkAddVerilogDirectives( Psr_Man_t * p ) -{ - int i; - for ( i = 1; s_VerTypes[i]; i++ ) - Abc_NamStrFindOrAdd( p->pStrs, (char *)s_VerTypes[i], NULL ); - assert( Abc_NamObjNumMax(p->pStrs) == i ); -} - - -// character recognition -static inline int Psr_CharIsSpace( char c ) { return (c == ' ' || c == '\t' || c == '\r' || c == '\n'); } -static inline int Psr_CharIsDigit( char c ) { return (c >= '0' && c <= '9'); } -static inline int Psr_CharIsDigitB( char c ) { return (c == '0' || c == '1' || c == 'x' || c == 'z'); } -static inline int Psr_CharIsDigitH( char c ) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); } -static inline int Psr_CharIsChar( char c ) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } -static inline int Psr_CharIsSymb1( char c ) { return Psr_CharIsChar(c) || c == '_'; } -static inline int Psr_CharIsSymb2( char c ) { return Psr_CharIsSymb1(c) || Psr_CharIsDigit(c) || c == '$'; } - -static inline int Psr_ManIsChar( Psr_Man_t * p, char c ) { return p->pCur[0] == c; } -static inline int Psr_ManIsChar1( Psr_Man_t * p, char c ) { return p->pCur[1] == c; } -static inline int Psr_ManIsDigit( Psr_Man_t * p ) { return Psr_CharIsDigit(*p->pCur); } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - -// collect predefined modules names -static const char * s_VerilogModules[100] = -{ - "const0", // BAC_BOX_CF, - "const1", // BAC_BOX_CT, - "constX", // BAC_BOX_CX, - "constZ", // BAC_BOX_CZ, - "buf", // BAC_BOX_BUF, - "not", // BAC_BOX_INV, - "and", // BAC_BOX_AND, - "nand", // BAC_BOX_NAND, - "or", // BAC_BOX_OR, - "nor", // BAC_BOX_NOR, - "xor", // BAC_BOX_XOR, - "xnor", // BAC_BOX_XNOR, - "sharp", // BAC_BOX_SHARP, - "mux", // BAC_BOX_MUX, - "maj", // BAC_BOX_MAJ, - NULL -}; -static const char * s_KnownModules[100] = -{ - "VERIFIC_", - "add_", - "mult_", - "div_", - "mod_", - "rem_", - "shift_left_", - "shift_right_", - "rotate_left_", - "rotate_right_", - "reduce_and_", - "reduce_or_", - "reduce_xor_", - "reduce_nand_", - "reduce_nor_", - "reduce_xnor_", - "LessThan_", - "Mux_", - "Select_", - "Decoder_", - "EnabledDecoder_", - "PrioSelect_", - "DualPortRam_", - "ReadPort_", - "WritePort_", - "ClockedWritePort_", - "lut", - "and_", - "or_", - "xor_", - "nand_", - "nor_", - "xnor_", - "buf_", - "inv_", - "tri_", - "sub_", - "unary_minus_", - "equal_", - "not_equal_", - "mux_", - "wide_mux_", - "wide_select_", - "wide_dff_", - "wide_dlatch_", - "wide_dffrs_", - "wide_dlatchrs_", - "wide_prio_select_", - "pow_", - "PrioEncoder_", - "abs", - NULL -}; - -// check if it is a Verilog predefined module -static inline int Psr_ManIsVerilogModule( Psr_Man_t * p, char * pName ) -{ - int i; - for ( i = 0; s_VerilogModules[i]; i++ ) - if ( !strcmp(pName, s_VerilogModules[i]) ) - return BAC_BOX_CF + i; - return 0; -} -// check if it is a known module -static inline int Psr_ManIsKnownModule( Psr_Man_t * p, char * pName ) -{ - int i; - for ( i = 0; s_KnownModules[i]; i++ ) - if ( !strncmp(pName, s_KnownModules[i], strlen(s_KnownModules[i])) ) - return i; - return 0; -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - -// skips Verilog comments (returns 1 if some comments were skipped) -static inline int Psr_ManUtilSkipComments( Psr_Man_t * p ) -{ - if ( !Psr_ManIsChar(p, '/') ) - return 0; - if ( Psr_ManIsChar1(p, '/') ) - { - for ( p->pCur += 2; p->pCur < p->pLimit; p->pCur++ ) - if ( Psr_ManIsChar(p, '\n') ) - { p->pCur++; return 1; } - } - else if ( Psr_ManIsChar1(p, '*') ) - { - for ( p->pCur += 2; p->pCur < p->pLimit; p->pCur++ ) - if ( Psr_ManIsChar(p, '*') && Psr_ManIsChar1(p, '/') ) - { p->pCur++; p->pCur++; return 1; } - } - return 0; -} -static inline int Psr_ManUtilSkipName( Psr_Man_t * p ) -{ - if ( !Psr_ManIsChar(p, '\\') ) - return 0; - for ( p->pCur++; p->pCur < p->pLimit; p->pCur++ ) - if ( Psr_ManIsChar(p, ' ') ) - { p->pCur++; return 1; } - return 0; -} - -// skip any number of spaces and comments -static inline int Psr_ManUtilSkipSpaces( Psr_Man_t * p ) -{ - while ( p->pCur < p->pLimit ) - { - while ( Psr_CharIsSpace(*p->pCur) ) - p->pCur++; - if ( !*p->pCur ) - return Psr_ManErrorSet(p, "Unexpectedly reached end-of-file.", 1); - if ( !Psr_ManUtilSkipComments(p) ) - return 0; - } - return Psr_ManErrorSet(p, "Unexpectedly reached end-of-file.", 1); -} -// skip everything including comments until the given char -static inline int Psr_ManUtilSkipUntil( Psr_Man_t * p, char c ) -{ - while ( p->pCur < p->pLimit ) - { - if ( Psr_ManIsChar(p, c) ) - return 1; - if ( Psr_ManUtilSkipComments(p) ) - continue; - if ( Psr_ManUtilSkipName(p) ) - continue; - p->pCur++; - } - return 0; -} -// skip everything including comments until the given word -static inline int Psr_ManUtilSkipUntilWord( Psr_Man_t * p, char * pWord ) -{ - char * pPlace = strstr( p->pCur, pWord ); - if ( pPlace == NULL ) return 1; - p->pCur = pPlace + strlen(pWord); - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_ManReadName( Psr_Man_t * p ) -{ - char * pStart = p->pCur; - if ( Psr_ManIsChar(p, '\\') ) // escaped name - { - pStart = ++p->pCur; - while ( !Psr_ManIsChar(p, ' ') ) - p->pCur++; - } - else if ( Psr_CharIsSymb1(*p->pCur) ) // simple name - { - p->pCur++; - while ( Psr_CharIsSymb2(*p->pCur) ) - p->pCur++; - } - else - return 0; - return Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur, NULL ); -} -static inline int Psr_ManReadNameList( Psr_Man_t * p, Vec_Int_t * vTemp, char LastSymb ) -{ - Vec_IntClear( vTemp ); - while ( 1 ) - { - int Item = Psr_ManReadName(p); - if ( Item == 0 ) return Psr_ManErrorSet(p, "Cannot read name in the list.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 1.", 0); - if ( Item == PRS_VER_WIRE ) - continue; - Vec_IntPush( vTemp, Item ); - if ( Psr_ManIsChar(p, LastSymb) ) break; - if ( !Psr_ManIsChar(p, ',') ) return Psr_ManErrorSet(p, "Expecting comma in the list.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 2.", 0); - } - return 1; -} -static inline int Psr_ManReadConstant( Psr_Man_t * p ) -{ - char * pStart = p->pCur; - assert( Psr_ManIsDigit(p) ); - while ( Psr_ManIsDigit(p) ) - p->pCur++; - if ( !Psr_ManIsChar(p, '\'') ) return Psr_ManErrorSet(p, "Cannot read constant.", 0); - p->pCur++; - if ( Psr_ManIsChar(p, 'b') ) - { - p->pCur++; - while ( Psr_CharIsDigitB(*p->pCur) ) - { - if ( *p->pCur == '0' ) - p->pNtk->fHasC0s = 1; - else if ( *p->pCur == '1' ) - p->pNtk->fHasC1s = 1; - else if ( *p->pCur == 'x' ) - p->pNtk->fHasCXs = 1; - else if ( *p->pCur == 'z' ) - p->pNtk->fHasCZs = 1; - p->pCur++; - } - } - else if ( Psr_ManIsChar(p, 'h') ) - { - p->pCur++; - p->pNtk->fHasC0s = 1; - while ( Psr_CharIsDigitH(*p->pCur) ) - { - if ( *p->pCur != '0' ) - p->pNtk->fHasC1s = 1; - p->pCur++; - } - } - else if ( Psr_ManIsChar(p, 'd') ) - { - p->pCur++; - p->pNtk->fHasC0s = 1; - while ( Psr_ManIsDigit(p) ) - { - if ( *p->pCur != '0' ) - p->pNtk->fHasC1s = 1; - p->pCur++; - } - } - else return Psr_ManErrorSet(p, "Cannot read radix of constant.", 0); - return Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur, NULL ); -} -static inline int Psr_ManReadRange( Psr_Man_t * p ) -{ - assert( Psr_ManIsChar(p, '[') ); - Vec_StrClear( &p->vCover ); - Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 3.", 0); - if ( !Psr_ManIsDigit(p) ) return Psr_ManErrorSet(p, "Cannot read digit in range specification.", 0); - while ( Psr_ManIsDigit(p) ) - Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 4.", 0); - if ( Psr_ManIsChar(p, ':') ) - { - Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 5.", 0); - if ( !Psr_ManIsDigit(p) ) return Psr_ManErrorSet(p, "Cannot read digit in range specification.", 0); - while ( Psr_ManIsDigit(p) ) - Vec_StrPush( &p->vCover, *p->pCur++ ); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 6.", 0); - } - if ( !Psr_ManIsChar(p, ']') ) return Psr_ManErrorSet(p, "Cannot read closing brace in range specification.", 0); - Vec_StrPush( &p->vCover, *p->pCur++ ); - Vec_StrPush( &p->vCover, '\0' ); - return Abc_NamStrFindOrAdd( p->pStrs, Vec_StrArray(&p->vCover), NULL ); -} -static inline int Psr_ManReadConcat( Psr_Man_t * p, Vec_Int_t * vTemp2 ) -{ - extern int Psr_ManReadSignalList( Psr_Man_t * p, Vec_Int_t * vTemp, char LastSymb, int fAddForm ); - assert( Psr_ManIsChar(p, '{') ); - p->pCur++; - if ( !Psr_ManReadSignalList( p, vTemp2, '}', 0 ) ) return Psr_ManErrorSet(p, "Error number 7.", 0); - // check final - assert( Psr_ManIsChar(p, '}') ); - p->pCur++; - // return special case - assert( Vec_IntSize(vTemp2) > 0 ); - if ( Vec_IntSize(vTemp2) == 1 ) - return Vec_IntEntry(vTemp2, 0); - return Abc_Var2Lit2( Psr_NtkAddConcat(p->pNtk, vTemp2), BAC_PRS_CONCAT ); -} -static inline int Psr_ManReadSignal( Psr_Man_t * p ) -{ - int Item; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 8.", 0); - if ( Psr_ManIsDigit(p) ) - { - Item = Psr_ManReadConstant(p); - if ( Item == 0 ) return Psr_ManErrorSet(p, "Error number 9.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 10.", 0); - return Abc_Var2Lit2( Item, BAC_PRS_CONST ); - } - if ( Psr_ManIsChar(p, '{') ) - { - if ( p->fUsingTemp2 ) return Psr_ManErrorSet(p, "Cannot read nested concatenations.", 0); - p->fUsingTemp2 = 1; - Item = Psr_ManReadConcat(p, &p->vTemp2); - p->fUsingTemp2 = 0; - if ( Item == 0 ) return Psr_ManErrorSet(p, "Error number 11.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 12.", 0); - return Item; - } - else - { - Item = Psr_ManReadName( p ); - if ( Item == 0 ) return Psr_ManErrorSet(p, "Error number 13.", 0); // was return 1; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 14.", 0); - if ( Psr_ManIsChar(p, '[') ) - { - int Range = Psr_ManReadRange(p); - if ( Range == 0 ) return Psr_ManErrorSet(p, "Error number 15.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 16.", 0); - return Abc_Var2Lit2( Psr_NtkAddSlice(p->pNtk, Item, Range), BAC_PRS_SLICE ); - } - return Abc_Var2Lit2( Item, BAC_PRS_NAME ); - } -} -int Psr_ManReadSignalList( Psr_Man_t * p, Vec_Int_t * vTemp, char LastSymb, int fAddForm ) -{ - Vec_IntClear( vTemp ); - while ( 1 ) - { - int Item = Psr_ManReadSignal(p); - if ( Item == 0 ) return Psr_ManErrorSet(p, "Cannot read signal in the list.", 0); - if ( fAddForm ) - Vec_IntPush( vTemp, 0 ); - Vec_IntPush( vTemp, Item ); - if ( Psr_ManIsChar(p, LastSymb) ) break; - if ( !Psr_ManIsChar(p, ',') ) return Psr_ManErrorSet(p, "Expecting comma in the list.", 0); - p->pCur++; - } - return 1; -} -static inline int Psr_ManReadSignalList2( Psr_Man_t * p, Vec_Int_t * vTemp ) -{ - int FormId, ActItem; - Vec_IntClear( vTemp ); - assert( Psr_ManIsChar(p, '.') ); - while ( Psr_ManIsChar(p, '.') ) - { - p->pCur++; - FormId = Psr_ManReadName( p ); - if ( FormId == 0 ) return Psr_ManErrorSet(p, "Cannot read formal name of the instance.", 0); - if ( !Psr_ManIsChar(p, '(') ) return Psr_ManErrorSet(p, "Cannot read \"(\" in the instance.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 17.", 0); - ActItem = Psr_ManReadSignal( p ); - if ( ActItem == 0 ) return Psr_ManErrorSet(p, "Cannot read actual name of the instance.", 0); - if ( !Psr_ManIsChar(p, ')') ) return Psr_ManErrorSet(p, "Cannot read \")\" in the instance.", 0); - p->pCur++; - Vec_IntPushTwo( vTemp, FormId, ActItem ); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 18.", 0); - if ( Psr_ManIsChar(p, ')') ) break; - if ( !Psr_ManIsChar(p, ',') ) return Psr_ManErrorSet(p, "Expecting comma in the instance.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 19.", 0); - } - assert( Vec_IntSize(vTemp) > 0 ); - assert( Vec_IntSize(vTemp) % 2 == 0 ); - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Psr_ManReadDeclaration( Psr_Man_t * p, int Type ) -{ - int i, NameId, RangeId = 0; - 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 ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 20.", 0); - if ( Psr_ManIsChar(p, '[') && !(RangeId = Psr_ManReadRange(p)) ) return Psr_ManErrorSet(p, "Error number 21.", 0); - if ( !Psr_ManReadNameList( p, &p->vTemp, ';' ) ) return Psr_ManErrorSet(p, "Error number 22.", 0); - Vec_IntForEachEntry( &p->vTemp, NameId, i ) - { - Vec_IntPush( vNames[Type - PRS_VER_INPUT], NameId ); - Vec_IntPush( vNamesR[Type - PRS_VER_INPUT], RangeId ); - if ( Type < PRS_VER_WIRE ) - Vec_IntPush( &p->pNtk->vOrder, Abc_Var2Lit2(NameId, Type) ); - } - return 1; -} -static inline int Psr_ManReadAssign( Psr_Man_t * p ) -{ - int OutItem, InItem, fCompl = 0, fCompl2 = 0, Oper = 0; - // read output name - OutItem = Psr_ManReadSignal( p ); - if ( OutItem == 0 ) return Psr_ManErrorSet(p, "Cannot read output in assign-statement.", 0); - if ( !Psr_ManIsChar(p, '=') ) return Psr_ManErrorSet(p, "Expecting \"=\" in assign-statement.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 23.", 0); - if ( Psr_ManIsChar(p, '~') ) - { - fCompl = 1; - p->pCur++; - } - // read first name - InItem = Psr_ManReadSignal( p ); - if ( InItem == 0 ) return Psr_ManErrorSet(p, "Cannot read first input name in the assign-statement.", 0); - Vec_IntClear( &p->vTemp ); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, InItem ); - // check unary operator - if ( Psr_ManIsChar(p, ';') ) - { - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, OutItem ); - Oper = fCompl ? BAC_BOX_INV : BAC_BOX_BUF; - Psr_NtkAddBox( p->pNtk, Oper, 0, &p->vTemp ); - return 1; - } - if ( Psr_ManIsChar(p, '&') ) - Oper = BAC_BOX_AND; - else if ( Psr_ManIsChar(p, '|') ) - Oper = BAC_BOX_OR; - else if ( Psr_ManIsChar(p, '^') ) - Oper = BAC_BOX_XOR; - else if ( Psr_ManIsChar(p, '?') ) - Oper = BAC_BOX_MUX; - else return Psr_ManErrorSet(p, "Unrecognized operator in the assign-statement.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 24.", 0); - if ( Psr_ManIsChar(p, '~') ) - { - fCompl2 = 1; - p->pCur++; - } - // read second name - InItem = Psr_ManReadSignal( p ); - if ( InItem == 0 ) return Psr_ManErrorSet(p, "Cannot read second input name in the assign-statement.", 0); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, InItem ); - // read third argument - if ( Oper == BAC_BOX_MUX ) - { - assert( fCompl == 0 ); - if ( !Psr_ManIsChar(p, ':') ) return Psr_ManErrorSet(p, "Expected colon in the MUX assignment.", 0); - p->pCur++; - // read third name - InItem = Psr_ManReadSignal( p ); - if ( InItem == 0 ) return Psr_ManErrorSet(p, "Cannot read third input name in the assign-statement.", 0); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, InItem ); - if ( !Psr_ManIsChar(p, ';') ) return Psr_ManErrorSet(p, "Expected semicolon at the end of the assign-statement.", 0); - } - else - { - // figure out operator - if ( Oper == BAC_BOX_AND ) - { - if ( fCompl && !fCompl2 ) - Oper = BAC_BOX_SHARPL; - else if ( !fCompl && fCompl2 ) - Oper = BAC_BOX_SHARP; - else if ( fCompl && fCompl2 ) - Oper = BAC_BOX_NOR; - } - else if ( Oper == BAC_BOX_OR ) - { - if ( fCompl && fCompl2 ) - Oper = BAC_BOX_NAND; - else assert( !fCompl && !fCompl2 ); - } - else if ( Oper == BAC_BOX_XOR ) - { - if ( fCompl && !fCompl2 ) - Oper = BAC_BOX_XNOR; - else assert( !fCompl && !fCompl2 ); - } - } - // write binary operator - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, OutItem ); - Psr_NtkAddBox( p->pNtk, Oper, 0, &p->vTemp ); - return 1; -} -static inline int Psr_ManReadInstance( Psr_Man_t * p, int Func ) -{ - int InstId, Status; -/* - static Counter = 0; - if ( ++Counter == 7 ) - { - int s=0; - } -*/ - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 25.", 0); - if ( (InstId = Psr_ManReadName(p)) ) - if (Psr_ManUtilSkipSpaces(p)) return Psr_ManErrorSet(p, "Error number 26.", 0); - if ( !Psr_ManIsChar(p, '(') ) return Psr_ManErrorSet(p, "Expecting \"(\" in module instantiation.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 27.", 0); - if ( Psr_ManIsChar(p, '.') ) // box - Status = Psr_ManReadSignalList2(p, &p->vTemp); - else // node - { - //char * s = Abc_NamStr(p->pStrs, Func); - // translate elementary gate - int iFuncNew = Psr_ManIsVerilogModule(p, Abc_NamStr(p->pStrs, Func)); - if ( iFuncNew == 0 ) return Psr_ManErrorSet(p, "Cannot find elementary gate.", 0); - Func = iFuncNew; - Status = Psr_ManReadSignalList( p, &p->vTemp, ')', 1 ); - } - if ( Status == 0 ) return Psr_ManErrorSet(p, "Error number 28.", 0); - assert( Psr_ManIsChar(p, ')') ); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 29.", 0); - if ( !Psr_ManIsChar(p, ';') ) return Psr_ManErrorSet(p, "Expecting semicolon in the instance.", 0); - // add box - Psr_NtkAddBox( p->pNtk, Func, InstId, &p->vTemp ); - return 1; -} -static inline int Psr_ManReadArguments( Psr_Man_t * p ) -{ - int iRange = 0, iType = -1; - Vec_Int_t * vSigs[3] = { &p->pNtk->vInputs, &p->pNtk->vOutputs, &p->pNtk->vInouts }; - Vec_Int_t * vSigsR[3] = { &p->pNtk->vInputsR, &p->pNtk->vOutputsR, &p->pNtk->vInoutsR }; - assert( Psr_ManIsChar(p, '(') ); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 30.", 0); - while ( 1 ) - { - int iName = Psr_ManReadName( p ); - if ( iName == 0 ) return Psr_ManErrorSet(p, "Error number 31.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 32.", 0); - if ( iName >= PRS_VER_INPUT && iName <= PRS_VER_INOUT ) // declaration - { - iType = iName; - if ( Psr_ManIsChar(p, '[') ) - { - iRange = Psr_ManReadRange(p); - if ( iRange == 0 ) return Psr_ManErrorSet(p, "Error number 33.", 0); - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 34.", 0); - } - iName = Psr_ManReadName( p ); - if ( iName == 0 ) return Psr_ManErrorSet(p, "Error number 35.", 0); - } - if ( iType > 0 ) - { - Vec_IntPush( vSigs[iType - PRS_VER_INPUT], iName ); - Vec_IntPush( vSigsR[iType - PRS_VER_INPUT], iRange ); - Vec_IntPush( &p->pNtk->vOrder, Abc_Var2Lit2(iName, iType) ); - } - if ( Psr_ManIsChar(p, ')') ) - break; - if ( !Psr_ManIsChar(p, ',') ) return Psr_ManErrorSet(p, "Expecting comma in the instance.", 0); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return Psr_ManErrorSet(p, "Error number 36.", 0); - } - // check final - assert( Psr_ManIsChar(p, ')') ); - return 1; -} -// this procedure can return: -// 0 = reached end-of-file; 1 = successfully parsed; 2 = recognized as primitive; 3 = failed and skipped; 4 = error (failed and could not skip) -static inline int Psr_ManReadModule( Psr_Man_t * p ) -{ - int iToken, Status; - if ( p->pNtk != NULL ) return Psr_ManErrorSet(p, "Parsing previous module is unfinished.", 4); - if ( Psr_ManUtilSkipSpaces(p) ) - { - Psr_ManErrorClear( p ); - return 0; - } - // read keyword - iToken = Psr_ManReadName( p ); - if ( iToken != PRS_VER_MODULE ) return Psr_ManErrorSet(p, "Cannot read \"module\" keyword.", 4); - if ( Psr_ManUtilSkipSpaces(p) ) return 4; - // read module name - iToken = Psr_ManReadName( p ); - if ( iToken == 0 ) return Psr_ManErrorSet(p, "Cannot read module name.", 4); - if ( Psr_ManIsKnownModule(p, Abc_NamStr(p->pStrs, iToken)) ) - { - if ( Psr_ManUtilSkipUntilWord( p, "endmodule" ) ) return Psr_ManErrorSet(p, "Cannot find \"endmodule\" keyword.", 4); - //printf( "Warning! Skipped known module \"%s\".\n", Abc_NamStr(p->pStrs, iToken) ); - Vec_IntPush( &p->vKnown, iToken ); - return 2; - } - Psr_ManInitializeNtk( p, iToken, 1 ); - // skip arguments - if ( Psr_ManUtilSkipSpaces(p) ) return 4; - if ( !Psr_ManIsChar(p, '(') ) return Psr_ManErrorSet(p, "Cannot find \"(\" in the argument declaration.", 4); - if ( !Psr_ManReadArguments(p) ) return 4; - assert( *p->pCur == ')' ); - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return 4; - // read declarations and instances - while ( Psr_ManIsChar(p, ';') ) - { - p->pCur++; - if ( Psr_ManUtilSkipSpaces(p) ) return 4; - iToken = Psr_ManReadName( p ); - if ( iToken == PRS_VER_ENDMODULE ) - { - Vec_IntPush( &p->vSucceeded, p->pNtk->iModuleName ); - Psr_ManFinalizeNtk( p ); - return 1; - } - if ( iToken >= PRS_VER_INPUT && iToken <= PRS_VER_WIRE ) // declaration - Status = Psr_ManReadDeclaration( p, iToken ); - else if ( iToken == PRS_VER_REG || iToken == PRS_VER_DEFPARAM ) // unsupported keywords - Status = Psr_ManUtilSkipUntil( p, ';' ); - else // read instance - { - if ( iToken == PRS_VER_ASSIGN ) - Status = Psr_ManReadAssign( p ); - else - Status = Psr_ManReadInstance( p, iToken ); - if ( Status == 0 ) - { - if ( Psr_ManUtilSkipUntilWord( p, "endmodule" ) ) return Psr_ManErrorSet(p, "Cannot find \"endmodule\" keyword.", 4); - //printf( "Warning! Failed to parse \"%s\". Adding module \"%s\" as blackbox.\n", - // Abc_NamStr(p->pStrs, iToken), Abc_NamStr(p->pStrs, p->pNtk->iModuleName) ); - Vec_IntPush( &p->vFailed, p->pNtk->iModuleName ); - // cleanup - Vec_IntErase( &p->pNtk->vWires ); - Vec_IntErase( &p->pNtk->vWiresR ); - Vec_IntErase( &p->pNtk->vSlices ); - Vec_IntErase( &p->pNtk->vConcats ); - Vec_IntErase( &p->pNtk->vBoxes ); - Vec_IntErase( &p->pNtk->vObjs ); - p->fUsingTemp2 = 0; - // add - Psr_ManFinalizeNtk( p ); - Psr_ManErrorClear( p ); - return 3; - } - } - if ( !Status ) return 4; - if ( Psr_ManUtilSkipSpaces(p) ) return 4; - } - return Psr_ManErrorSet(p, "Cannot find \";\" in the module definition.", 4); -} -static inline int Psr_ManReadDesign( Psr_Man_t * p ) -{ - while ( 1 ) - { - int RetValue = Psr_ManReadModule( p ); - if ( RetValue == 0 ) // end of file - break; - if ( RetValue == 1 ) // successfully parsed - continue; - if ( RetValue == 2 ) // recognized as primitive - continue; - if ( RetValue == 3 ) // failed and skipped - continue; - if ( RetValue == 4 ) // error - return 0; - assert( 0 ); - } - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Psr_ManPrintModules( Psr_Man_t * p ) -{ - char * pName; int i; - printf( "Succeeded parsing %d models:\n", Vec_IntSize(&p->vSucceeded) ); - Psr_ManForEachNameVec( &p->vSucceeded, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); - printf( "Skipped %d known models:\n", Vec_IntSize(&p->vKnown) ); - Psr_ManForEachNameVec( &p->vKnown, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); - printf( "Skipped %d failed models:\n", Vec_IntSize(&p->vFailed) ); - Psr_ManForEachNameVec( &p->vFailed, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Psr_ManReadVerilog( char * pFileName ) -{ - Vec_Ptr_t * vPrs = NULL; - Psr_Man_t * p = Psr_ManAlloc( pFileName ); - if ( p == NULL ) - return NULL; - Psr_NtkAddVerilogDirectives( p ); - Psr_ManReadDesign( p ); - //Psr_ManPrintModules( p ); - if ( Psr_ManErrorPrint(p) ) - ABC_SWAP( Vec_Ptr_t *, vPrs, p->vNtks ); - Psr_ManFree( p ); - return vPrs; -} - -void Psr_ManReadVerilogTest( char * pFileName ) -{ - abctime clk = Abc_Clock(); - extern void Psr_ManWriteVerilog( char * pFileName, Vec_Ptr_t * p ); - Vec_Ptr_t * vPrs = Psr_ManReadVerilog( "c/hie/dump/1/netlist_1.v" ); -// Vec_Ptr_t * vPrs = Psr_ManReadVerilog( "aga/me/me_wide.v" ); -// Vec_Ptr_t * vPrs = Psr_ManReadVerilog( "aga/ray/ray_wide.v" ); - if ( !vPrs ) return; - printf( "Finished reading %d networks. ", Vec_PtrSize(vPrs) ); - printf( "NameIDs = %d. ", Abc_NamObjNumMax(Psr_ManNameMan(vPrs)) ); - printf( "Memory = %.2f MB. ", 1.0*Psr_ManMemory(vPrs)/(1<<20) ); - Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); - Psr_ManWriteVerilog( "c/hie/dump/1/netlist_1_out_new.v", vPrs ); -// Psr_ManWriteVerilog( "aga/me/me_wide_out.v", vPrs ); -// Psr_ManWriteVerilog( "aga/ray/ray_wide_out.v", vPrs ); -// Abc_NamPrint( p->pStrs ); - Psr_ManVecFree( vPrs ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacWriteBlif.c b/src/base/bac/bacWriteBlif.c deleted file mode 100644 index ba2d2e50a..000000000 --- a/src/base/bac/bacWriteBlif.c +++ /dev/null @@ -1,236 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacWriteBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacWriteBlif.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" -#include "map/mio/mio.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Writing parser state into a file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Psr_ManWriteBlifArray( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vFanins ) -{ - int i, NameId; - Vec_IntForEachEntry( vFanins, NameId, i ) - fprintf( pFile, " %s", Psr_NtkStr(p, NameId) ); - fprintf( pFile, "\n" ); -} -static void Psr_ManWriteBlifLines( FILE * pFile, Psr_Ntk_t * p ) -{ - Vec_Int_t * vBox; - int i, k, FormId, ActId; - Psr_NtkForEachBox( p, vBox, i ) - { - int NtkId = Psr_BoxNtk(p, i); - assert( Psr_BoxIONum(p, i) > 0 ); - assert( Vec_IntSize(vBox) % 2 == 0 ); - if ( NtkId == -1 ) // latch - { - fprintf( pFile, ".latch" ); - fprintf( pFile, " %s", Psr_NtkStr(p, Vec_IntEntry(vBox, 1)) ); - fprintf( pFile, " %s", Psr_NtkStr(p, Vec_IntEntry(vBox, 3)) ); - fprintf( pFile, " %c\n", '0' + Psr_BoxName(p, i) ); - } - else if ( Psr_BoxIsNode(p, i) ) // node - { - fprintf( pFile, ".names" ); - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - fprintf( pFile, " %s", Psr_NtkStr(p, ActId) ); - fprintf( pFile, "\n%s", Psr_NtkStr(p, NtkId) ); - } - else // box - { - fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", Psr_NtkStr(p, NtkId) ); - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - fprintf( pFile, " %s=%s", Psr_NtkStr(p, FormId), Psr_NtkStr(p, ActId) ); - fprintf( pFile, "\n" ); - } - } -} -static void Psr_ManWriteBlifNtk( FILE * pFile, Psr_Ntk_t * p ) -{ - // write header - fprintf( pFile, ".model %s\n", Psr_NtkStr(p, p->iModuleName) ); - if ( Vec_IntSize(&p->vInouts) ) - fprintf( pFile, ".inouts" ); - if ( Vec_IntSize(&p->vInouts) ) - Psr_ManWriteBlifArray( pFile, p, &p->vInouts ); - fprintf( pFile, ".inputs" ); - Psr_ManWriteBlifArray( pFile, p, &p->vInputs ); - fprintf( pFile, ".outputs" ); - Psr_ManWriteBlifArray( pFile, p, &p->vOutputs ); - // write objects - Psr_ManWriteBlifLines( pFile, p ); - fprintf( pFile, ".end\n\n" ); -} -void Psr_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ) -{ - Psr_Ntk_t * pNtk = Psr_ManRoot(vPrs); - FILE * pFile = fopen( pFileName, "wb" ); int i; - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "# Design \"%s\" written by ABC on %s\n\n", Psr_NtkStr(pNtk, pNtk->iModuleName), Extra_TimeStamp() ); - Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i ) - Psr_ManWriteBlifNtk( pFile, pNtk ); - fclose( pFile ); -} - - - -/**Function************************************************************* - - Synopsis [Write elaborated design.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Bac_ManWriteBlifGate( FILE * pFile, Bac_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), Bac_ObjNameStr(p, iFanin) ); - fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate), Bac_ObjNameStr(p, iObj) ); - fprintf( pFile, "\n" ); -} -void Bac_ManWriteBlifArray( FILE * pFile, Bac_Ntk_t * p, Vec_Int_t * vFanins, int iObj ) -{ - int iFanin, i; - Vec_IntForEachEntry( vFanins, iFanin, i ) - fprintf( pFile, " %s", Bac_ObjNameStr(p, iFanin) ); - if ( iObj >= 0 ) - fprintf( pFile, " %s", Bac_ObjNameStr(p, iObj) ); - fprintf( pFile, "\n" ); -} -void Bac_ManWriteBlifArray2( FILE * pFile, Bac_Ntk_t * p, int iObj ) -{ - int iTerm, i; - Bac_Ntk_t * pModel = Bac_BoxNtk( p, iObj ); - Bac_NtkForEachPi( pModel, iTerm, i ) - fprintf( pFile, " %s=%s", Bac_ObjNameStr(pModel, iTerm), Bac_ObjNameStr(p, Bac_BoxBi(p, iObj, i)) ); - Bac_NtkForEachPo( pModel, iTerm, i ) - fprintf( pFile, " %s=%s", Bac_ObjNameStr(pModel, iTerm), Bac_ObjNameStr(p, Bac_BoxBo(p, iObj, i)) ); - fprintf( pFile, "\n" ); -} -void Bac_ManWriteBlifLines( FILE * pFile, Bac_Ntk_t * p ) -{ - int i, k, iTerm; - Bac_NtkForEachBox( p, i ) - { - if ( Bac_ObjIsBoxUser(p, i) ) - { - fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", Bac_NtkName(Bac_BoxNtk(p, i)) ); - Bac_ManWriteBlifArray2( pFile, p, i ); - } - else if ( Bac_ObjIsGate(p, i) ) - { - char * pGateName = Abc_NamStr(p->pDesign->pMods, Bac_BoxNtkId(p, i)); - Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - Mio_Gate_t * pGate = Mio_LibraryReadGateByName( pLib, pGateName, NULL ); - fprintf( pFile, ".gate %s", pGateName ); - Bac_BoxForEachBi( p, i, iTerm, k ) - fprintf( pFile, " %s=%s", Mio_GateReadPinName(pGate, k), Bac_ObjNameStr(p, iTerm) ); - Bac_BoxForEachBo( p, i, iTerm, k ) - fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate), Bac_ObjNameStr(p, iTerm) ); - fprintf( pFile, "\n" ); - } - else - { - fprintf( pFile, ".names" ); - Bac_BoxForEachBi( p, i, iTerm, k ) - fprintf( pFile, " %s", Bac_ObjNameStr(p, Bac_ObjFanin(p, iTerm)) ); - Bac_BoxForEachBo( p, i, iTerm, k ) - fprintf( pFile, " %s", Bac_ObjNameStr(p, iTerm) ); - fprintf( pFile, "\n%s", Ptr_TypeToSop(Bac_ObjType(p, i)) ); - } - } -} -void Bac_ManWriteBlifNtk( FILE * pFile, Bac_Ntk_t * p ) -{ - assert( Vec_IntSize(&p->vFanin) == Bac_NtkObjNum(p) ); - // write header - fprintf( pFile, ".model %s\n", Bac_NtkName(p) ); - fprintf( pFile, ".inputs" ); - Bac_ManWriteBlifArray( pFile, p, &p->vInputs, -1 ); - fprintf( pFile, ".outputs" ); - Bac_ManWriteBlifArray( pFile, p, &p->vOutputs, -1 ); - // write objects - Bac_ManWriteBlifLines( pFile, p ); - fprintf( pFile, ".end\n\n" ); -} -void Bac_ManWriteBlif( char * pFileName, Bac_Man_t * p ) -{ - FILE * pFile; - Bac_Ntk_t * pNtk; - int i; - // check the library - if ( p->pMioLib && p->pMioLib != Abc_FrameReadLibGen() ) - { - printf( "Genlib library used in the mapped design is not longer a current library.\n" ); - return; - } - pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "# Design \"%s\" written via CBA package in ABC on %s\n\n", Bac_ManName(p), Extra_TimeStamp() ); - Bac_ManAssignInternWordNames( p ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_ManWriteBlifNtk( pFile, pNtk ); - fclose( pFile ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacWriteSmt.c b/src/base/bac/bacWriteSmt.c deleted file mode 100644 index eacc5a06e..000000000 --- a/src/base/bac/bacWriteSmt.c +++ /dev/null @@ -1,52 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacWriteSmt.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacWriteSmt.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/bacWriteVer.c b/src/base/bac/bacWriteVer.c deleted file mode 100644 index 0f00eeef3..000000000 --- a/src/base/bac/bacWriteVer.c +++ /dev/null @@ -1,703 +0,0 @@ -/**CFile**************************************************************** - - FileName [bacWriteVer.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog writer.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: bacWriteVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "bac.h" -#include "bacPrs.h" -#include "map/mio/mio.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Writing parser state into a file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Psr_ManWriteVerilogConcat( FILE * pFile, Psr_Ntk_t * p, int Con ) -{ - extern void Psr_ManWriteVerilogArray( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vSigs, int Start, int Stop, int fOdd ); - Vec_Int_t * vSigs = Psr_CatSignals(p, Con); - fprintf( pFile, "{" ); - Psr_ManWriteVerilogArray( pFile, p, vSigs, 0, Vec_IntSize(vSigs), 0 ); - fprintf( pFile, "}" ); -} -static void Psr_ManWriteVerilogSignal( FILE * pFile, Psr_Ntk_t * p, int Sig ) -{ - int Value = Abc_Lit2Var2( Sig ); - Psr_ManType_t Type = (Psr_ManType_t)Abc_Lit2Att2( Sig ); - if ( Type == BAC_PRS_NAME || Type == BAC_PRS_CONST ) - fprintf( pFile, "%s", Psr_NtkStr(p, Value) ); - else if ( Type == BAC_PRS_SLICE ) - fprintf( pFile, "%s%s", Psr_NtkStr(p, Psr_SliceName(p, Value)), Psr_NtkStr(p, Psr_SliceRange(p, Value)) ); - else if ( Type == BAC_PRS_CONCAT ) - Psr_ManWriteVerilogConcat( pFile, p, Value ); - else assert( 0 ); -} -void Psr_ManWriteVerilogArray( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vSigs, int Start, int Stop, int fOdd ) -{ - int i, Sig; - assert( Vec_IntSize(vSigs) > 0 ); - Vec_IntForEachEntryStartStop( vSigs, Sig, i, Start, Stop ) - { - if ( fOdd && !(i & 1) ) - continue; - Psr_ManWriteVerilogSignal( pFile, p, Sig ); - fprintf( pFile, "%s", i == Stop - 1 ? "" : ", " ); - } -} -static void Psr_ManWriteVerilogArray2( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, FormId, ActSig; - assert( Vec_IntSize(vSigs) % 2 == 0 ); - Vec_IntForEachEntryDouble( vSigs, FormId, ActSig, i ) - { - fprintf( pFile, "." ); - fprintf( pFile, "%s", Psr_NtkStr(p, FormId) ); - fprintf( pFile, "(" ); - Psr_ManWriteVerilogSignal( pFile, p, ActSig ); - fprintf( pFile, ")%s", (i == Vec_IntSize(vSigs) - 2) ? "" : ", " ); - } -} -static void Psr_ManWriteVerilogMux( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, FormId, ActSig; - char * pStrs[4] = { " = ", " ? ", " : ", ";\n" }; - assert( Vec_IntSize(vSigs) == 8 ); - fprintf( pFile, " assign " ); - Psr_ManWriteVerilogSignal( pFile, p, Vec_IntEntryLast(vSigs) ); - fprintf( pFile, "%s", pStrs[0] ); - Vec_IntForEachEntryDouble( vSigs, FormId, ActSig, i ) - { - Psr_ManWriteVerilogSignal( pFile, p, ActSig ); - fprintf( pFile, "%s", pStrs[1+i/2] ); - if ( i == 4 ) - break; - } -} -static void Psr_ManWriteVerilogBoxes( FILE * pFile, Psr_Ntk_t * p ) -{ - Vec_Int_t * vBox; int i; - Psr_NtkForEachBox( p, vBox, i ) - { - Bac_ObjType_t NtkId = (Bac_ObjType_t)Psr_BoxNtk(p, i); - if ( NtkId == BAC_BOX_MUX ) - Psr_ManWriteVerilogMux( pFile, p, vBox ); - else if ( Psr_BoxIsNode(p, i) ) // node ------- check order of fanins - { - fprintf( pFile, " %s (", Ptr_TypeToName(NtkId) ); - Psr_ManWriteVerilogSignal( pFile, p, Vec_IntEntryLast(vBox) ); - if ( Psr_BoxIONum(p, i) > 1 ) - fprintf( pFile, ", " ); - Psr_ManWriteVerilogArray( pFile, p, vBox, 0, Vec_IntSize(vBox)-2, 1 ); - fprintf( pFile, ");\n" ); - } - else // box - { - //char * s = Psr_NtkStr(p, Vec_IntEntry(vBox, 0)); - fprintf( pFile, " %s %s (", Psr_NtkStr(p, NtkId), Psr_BoxName(p, i) ? Psr_NtkStr(p, Psr_BoxName(p, i)) : "" ); - Psr_ManWriteVerilogArray2( pFile, p, vBox ); - fprintf( pFile, ");\n" ); - } - } -} -static void Psr_ManWriteVerilogIos( FILE * pFile, Psr_Ntk_t * p, int SigType ) -{ - int NameId, RangeId, i; - char * pSigNames[4] = { "inout", "input", "output", "wire" }; - Vec_Int_t * vSigs[4] = { &p->vInouts, &p->vInputs, &p->vOutputs, &p->vWires }; - Vec_Int_t * vSigsR[4] = { &p->vInoutsR, &p->vInputsR, &p->vOutputsR, &p->vWiresR }; - if ( SigType == 3 ) - fprintf( pFile, "\n" ); - Vec_IntForEachEntryTwo( vSigs[SigType], vSigsR[SigType], NameId, RangeId, i ) - fprintf( pFile, " %s %s%s;\n", pSigNames[SigType], RangeId ? Psr_NtkStr(p, RangeId) : "", Psr_NtkStr(p, NameId) ); -} -static void Psr_ManWriteVerilogIoOrder( FILE * pFile, Psr_Ntk_t * p, Vec_Int_t * vOrder ) -{ - int i, NameId; - Vec_IntForEachEntry( vOrder, NameId, i ) - fprintf( pFile, "%s%s", Psr_NtkStr(p, NameId), i == Vec_IntSize(vOrder) - 1 ? "" : ", " ); -} -static void Psr_ManWriteVerilogNtk( FILE * pFile, Psr_Ntk_t * p ) -{ - int s; - // write header - fprintf( pFile, "module %s (\n ", Psr_NtkStr(p, p->iModuleName) ); - Psr_ManWriteVerilogIoOrder( pFile, p, &p->vOrder ); - fprintf( pFile, "\n );\n" ); - // write declarations - for ( s = 0; s < 4; s++ ) - Psr_ManWriteVerilogIos( pFile, p, s ); - fprintf( pFile, "\n" ); - // write objects - Psr_ManWriteVerilogBoxes( pFile, p ); - fprintf( pFile, "endmodule\n\n" ); -} -void Psr_ManWriteVerilog( char * pFileName, Vec_Ptr_t * vPrs ) -{ - Psr_Ntk_t * pNtk = Psr_ManRoot(vPrs); int i; - FILE * pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Psr_NtkStr(pNtk, pNtk->iModuleName), Extra_TimeStamp() ); - Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i ) - Psr_ManWriteVerilogNtk( pFile, pNtk ); - fclose( pFile ); -} - - - -/**Function************************************************************* - - Synopsis [Writing word-level Verilog.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -// compute range of a name (different from range of a multi-bit wire) -static inline int Bac_ObjGetRange( Bac_Ntk_t * p, int iObj ) -{ - int i, NameId = Bac_ObjName(p, iObj); - assert( Bac_ObjIsCi(p, iObj) ); -// if ( Bac_NameType(NameId) == BAC_NAME_INDEX ) -// NameId = Bac_ObjName(p, iObj - Abc_Lit2Var2(NameId)); - assert( Bac_NameType(NameId) == BAC_NAME_WORD || Bac_NameType(NameId) == BAC_NAME_INFO ); - for ( i = iObj + 1; i < Bac_NtkObjNum(p); i++ ) - if ( !Bac_ObjIsCi(p, i) || Bac_ObjNameType(p, i) != BAC_NAME_INDEX ) - break; - return i - iObj; -} - -static inline void Bac_ManWriteVar( Bac_Ntk_t * p, int RealName ) -{ - Vec_StrPrintStr( p->pDesign->vOut, Bac_NtkStr(p, RealName) ); -} -static inline void Bac_ManWriteRange( Bac_Ntk_t * p, int Beg, int End ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; - Vec_StrPrintStr( vStr, "[" ); - if ( End >= 0 ) - { - Vec_StrPrintNum( vStr, End ); - Vec_StrPrintStr( vStr, ":" ); - } - Vec_StrPrintNum( vStr, Beg ); - Vec_StrPrintStr( vStr, "]" ); -} -static inline void Bac_ManWriteConstBit( Bac_Ntk_t * p, int iObj, int fHead ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; - int Const = Bac_ObjGetConst(p, iObj); - assert( Const ); - if ( fHead ) - Vec_StrPrintStr( vStr, "1\'b" ); - if ( Const == BAC_BOX_CF ) - Vec_StrPush( vStr, '0' ); - else if ( Const == BAC_BOX_CT ) - Vec_StrPush( vStr, '1' ); - else if ( Const == BAC_BOX_CX ) - Vec_StrPush( vStr, 'x' ); - else if ( Const == BAC_BOX_CZ ) - Vec_StrPush( vStr, 'z' ); - else assert( 0 ); -} -static inline int Bac_ManFindRealNameId( Bac_Ntk_t * p, int iObj ) -{ - int NameId = Bac_ObjName(p, iObj); - assert( Bac_ObjIsCi(p, iObj) ); - if ( Bac_NameType(NameId) == BAC_NAME_INDEX ) - NameId = Bac_ObjName(p, iObj - Abc_Lit2Var2(NameId)); - if ( Bac_NameType(NameId) == BAC_NAME_INFO ) - return Bac_NtkInfoName(p, Abc_Lit2Var2(NameId)); - assert( Bac_NameType(NameId) == BAC_NAME_BIN || Bac_NameType(NameId) == BAC_NAME_WORD ); - return Abc_Lit2Var2(NameId); -} -static inline int Bac_ManFindRealIndex( Bac_Ntk_t * p, int iObj ) -{ - int iBit = 0, NameId = Bac_ObjName(p, iObj); - assert( Bac_ObjIsCi(p, iObj) ); - assert( Bac_NameType(NameId) != BAC_NAME_BIN ); - if ( Bac_NameType(NameId) == BAC_NAME_INDEX ) - NameId = Bac_ObjName(p, iObj - (iBit = Abc_Lit2Var2(NameId))); - if ( Bac_NameType(NameId) == BAC_NAME_INFO ) - return Bac_NtkInfoIndex(p, Abc_Lit2Var2(NameId), iBit); - assert( Bac_NameType(NameId) == BAC_NAME_WORD ); - return iBit; -} -static inline void Bac_ManWriteSig( Bac_Ntk_t * p, int iObj ) -{ - if ( Bac_ObjIsCo(p, iObj) ) - iObj = Bac_ObjFanin(p, iObj); - assert( Bac_ObjIsCi(p, iObj) ); - if ( Bac_ObjGetConst(p, iObj) ) - Bac_ManWriteConstBit( p, iObj, 1 ); - else - { - int NameId = Bac_ObjName(p, iObj); - if ( Bac_NameType(NameId) == BAC_NAME_BIN ) - Bac_ManWriteVar( p, Abc_Lit2Var2(NameId) ); - else - { - Bac_ManWriteVar( p, Bac_ManFindRealNameId(p, iObj) ); - Bac_ManWriteRange( p, Bac_ManFindRealIndex(p, iObj), -1 ); - } - } -} -static inline void Bac_ManWriteConcat( Bac_Ntk_t * p, int iStart, int nObjs ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; - assert( nObjs >= 1 ); - if ( nObjs == 1 ) - { - Bac_ManWriteSig( p, iStart ); - return; - } - Vec_StrPrintStr( vStr, "{" ); - if ( Bac_ObjIsBo(p, iStart) ) // box output - { - int i; - for ( i = iStart + nObjs - 1; i >= iStart; i-- ) - { - if ( Bac_ObjNameType(p, i) == BAC_NAME_INDEX ) - continue; - if ( Vec_StrEntryLast(vStr) != '{' ) - Vec_StrPrintStr( vStr, ", " ); - Bac_ManWriteVar( p, Bac_ManFindRealNameId(p, i) ); - } - } - else if ( Bac_ObjIsBi(p, iStart) ) // box input - { - int e, b, k, NameId; - for ( e = iStart - nObjs + 1; e <= iStart; ) - { - if ( Vec_StrEntryLast(vStr) != '{' ) - Vec_StrPrintStr( vStr, ", " ); - // write constant - if ( Bac_ObjGetConst(p, Bac_ObjFanin(p, e)) ) - { - int fBinary = Bac_ObjIsConstBin(p, Bac_ObjFanin(p, e)-1); - for ( b = e + 1; b <= iStart; b++ ) - { - if ( !Bac_ObjGetConst(p, Bac_ObjFanin(p, b)) ) - break; - if ( !Bac_ObjIsConstBin(p, Bac_ObjFanin(p, b)-1) ) - fBinary = 0; - } - Vec_StrPrintNum( vStr, b - e ); - if ( fBinary && b - e > 8 ) // write hex if more than 8 bits - { - int Digit = 0, nBits = ((b - e) & 3) ? (b - e) & 3 : 4; - Vec_StrPrintStr( vStr, "\'h" ); - for ( k = e; k < b; k++ ) - { - Digit = 2*Digit + Bac_ObjGetConst(p, Bac_ObjFanin(p, k)) - BAC_BOX_CF; - assert( Digit < 16 ); - if ( --nBits == 0 ) - { - Vec_StrPush( vStr, (char)(Digit < 10 ? '0' + Digit : 'a' + Digit - 10) ); - nBits = 4; - Digit = 0; - } - } - assert( nBits == 4 ); - assert( Digit == 0 ); - } - else - { - Vec_StrPrintStr( vStr, "\'b" ); - for ( k = e; k < b; k++ ) - Bac_ManWriteConstBit( p, Bac_ObjFanin(p, k), 0 ); - } - e = b; - continue; - } - // try replication - for ( b = e + 1; b <= iStart; b++ ) - if ( Bac_ObjFanin(p, b) != Bac_ObjFanin(p, e) ) - break; - if ( b > e + 2 ) // more than two - { - Vec_StrPrintNum( vStr, b - e ); - Vec_StrPrintStr( vStr, "{" ); - Bac_ManWriteSig( p, e ); - Vec_StrPrintStr( vStr, "}" ); - e = b; - continue; - } - NameId = Bac_ObjName(p, Bac_ObjFanin(p, e)); - if ( Bac_NameType(NameId) == BAC_NAME_BIN ) - { - Bac_ManWriteVar( p, Abc_Lit2Var2(NameId) ); - e++; - continue; - } - // find end of the slice - for ( b = e + 1; b <= iStart; b++ ) - if ( Bac_ObjFanin(p, e) - Bac_ObjFanin(p, b) != b - e ) - break; - // write signal name - Bac_ManWriteVar( p, Bac_ManFindRealNameId(p, Bac_ObjFanin(p, e)) ); - if ( b == e + 1 ) // literal - Bac_ManWriteRange( p, Bac_ManFindRealIndex(p, Bac_ObjFanin(p, e)), -1 ); - else // slice or complete variable - { - // consider first variable of the slice - int f = Bac_ObjFanin( p, b-1 ); - assert( Bac_ObjNameType(p, f) != BAC_NAME_BIN ); - if ( Bac_ObjNameType(p, f) == BAC_NAME_INDEX || Bac_ObjGetRange(p, f) != b - e ) // slice - Bac_ManWriteRange( p, Bac_ManFindRealIndex(p, f), Bac_ManFindRealIndex(p, Bac_ObjFanin(p, e)) ); - // else this is complete variable - } - e = b; - } - } - else assert( 0 ); - Vec_StrPrintStr( vStr, "}" ); -} -static inline void Bac_ManWriteGate( Bac_Ntk_t * p, int iObj ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; int iTerm, k; - char * pGateName = Abc_NamStr(p->pDesign->pMods, Bac_BoxNtkId(p, iObj)); - Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); - Mio_Gate_t * pGate = Mio_LibraryReadGateByName( pLib, pGateName, NULL ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, pGateName ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Bac_ObjName(p, iObj) ? Bac_ObjNameStr(p, iObj) : "" ); - Vec_StrPrintStr( vStr, " (" ); - Bac_BoxForEachBi( p, iObj, iTerm, k ) - { - Vec_StrPrintStr( vStr, k ? ", ." : "." ); - Vec_StrPrintStr( vStr, Mio_GateReadPinName(pGate, k) ); - Vec_StrPrintStr( vStr, "(" ); - Bac_ManWriteSig( p, iTerm ); - Vec_StrPrintStr( vStr, ")" ); - } - Bac_BoxForEachBo( p, iObj, iTerm, k ) - { - Vec_StrPrintStr( vStr, Bac_BoxBiNum(p, iObj) ? ", ." : "." ); - Vec_StrPrintStr( vStr, Mio_GateReadOutName(pGate) ); - Vec_StrPrintStr( vStr, "(" ); - Bac_ManWriteSig( p, iTerm ); - Vec_StrPrintStr( vStr, ")" ); - } - Vec_StrPrintStr( vStr, ");\n" ); -} -static inline void Bac_ManWriteAssign( Bac_Ntk_t * p, int iObj ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; - Bac_ObjType_t Type = Bac_ObjType(p, iObj); - int nInputs = Bac_BoxBiNum(p, iObj); - int nOutputs = Bac_BoxBoNum(p, iObj); - assert( nOutputs == 1 ); - Vec_StrPrintStr( vStr, " assign " ); - Bac_ManWriteSig( p, iObj + 1 ); - Vec_StrPrintStr( vStr, " = " ); - if ( nInputs == 0 ) - { - if ( Type == BAC_BOX_CF ) - Vec_StrPrintStr( vStr, "1\'b0" ); - else if ( Type == BAC_BOX_CT ) - Vec_StrPrintStr( vStr, "1\'b1" ); - else if ( Type == BAC_BOX_CX ) - Vec_StrPrintStr( vStr, "1\'bx" ); - else if ( Type == BAC_BOX_CZ ) - Vec_StrPrintStr( vStr, "1\'bz" ); - else assert( 0 ); - } - else if ( nInputs == 1 ) - { - if ( Type == BAC_BOX_INV ) - Vec_StrPrintStr( vStr, "~" ); - else assert( Type == BAC_BOX_BUF ); - Bac_ManWriteSig( p, iObj - 1 ); - } - else if ( nInputs == 2 ) - { - if ( Type == BAC_BOX_NAND || Type == BAC_BOX_NOR || Type == BAC_BOX_XNOR || Type == BAC_BOX_SHARPL ) - Vec_StrPrintStr( vStr, "~" ); - Bac_ManWriteSig( p, iObj - 1 ); - if ( Type == BAC_BOX_AND || Type == BAC_BOX_SHARPL ) - Vec_StrPrintStr( vStr, " & " ); - else if ( Type == BAC_BOX_SHARP || Type == BAC_BOX_NOR ) - Vec_StrPrintStr( vStr, " & ~" ); - else if ( Type == BAC_BOX_OR ) - Vec_StrPrintStr( vStr, " | " ); - else if ( Type == BAC_BOX_NAND ) - Vec_StrPrintStr( vStr, " | ~" ); - else if ( Type == BAC_BOX_XOR || Type == BAC_BOX_XNOR ) - Vec_StrPrintStr( vStr, " ^ " ); - else assert( 0 ); - Bac_ManWriteSig( p, iObj - 2 ); - } - Vec_StrPrintStr( vStr, ";\n" ); -} -void Bac_ManWriteVerilogBoxes( Bac_Ntk_t * p, int fUseAssign ) -{ - Vec_Str_t * vStr = p->pDesign->vOut; - int iObj, k, i, o, StartPos; - Bac_NtkForEachBox( p, iObj ) // .subckt/.gate/box (formal/actual binding) - { - // skip constants - if ( Bac_ObjIsConst(p, iObj) ) - continue; - // write mapped - if ( Bac_ObjIsGate(p, iObj) ) - { - Bac_ManWriteGate( p, iObj ); - continue; - } - // write primitives as assign-statements - if ( !Bac_ObjIsBoxUser(p, iObj) && fUseAssign ) - { - Bac_ManWriteAssign( p, iObj ); - continue; - } - // write header - StartPos = Vec_StrSize(vStr); - if ( Bac_ObjIsBoxUser(p, iObj) ) - { - int Value, Beg, End, Range; - Bac_Ntk_t * pModel = Bac_BoxNtk( p, iObj ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Bac_NtkName(pModel) ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Bac_ObjName(p, iObj) ? Bac_ObjNameStr(p, iObj) : "" ); - Vec_StrPrintStr( vStr, " (" ); - // write arguments - i = o = 0; - assert( Bac_NtkInfoNum(pModel) ); - Vec_IntForEachEntryTriple( &pModel->vInfo, Value, Beg, End, k ) - { - int NameId = Abc_Lit2Var2( Value ); - int Type = Abc_Lit2Att2( Value ); - Vec_StrPrintStr( vStr, k ? ", " : "" ); - if ( Vec_StrSize(vStr) > StartPos + 70 ) - { - StartPos = Vec_StrSize(vStr); - Vec_StrPrintStr( vStr, "\n " ); - } - Vec_StrPrintStr( vStr, "." ); - Vec_StrPrintStr( vStr, Bac_NtkStr(p, NameId) ); - Vec_StrPrintStr( vStr, "(" ); - Range = Bac_InfoRange( Beg, End ); - assert( Range > 0 ); - if ( Type == 1 ) - Bac_ManWriteConcat( p, Bac_BoxBi(p, iObj, i), Range ), i += Range; - else if ( Type == 2 ) - Bac_ManWriteConcat( p, Bac_BoxBo(p, iObj, o), Range ), o += Range; - else assert( 0 ); - Vec_StrPrintStr( vStr, ")" ); - } - assert( i == Bac_BoxBiNum(p, iObj) ); - assert( o == Bac_BoxBoNum(p, iObj) ); - } - else - { - int iTerm, k, Range, iSig = 0; - Vec_Int_t * vBits = Bac_BoxCollectRanges( p, iObj ); - char * pName = Bac_NtkGenerateName( p, Bac_ObjType(p, iObj), vBits ); - char * pSymbs = Bac_ManPrimSymb( p->pDesign, Bac_ObjType(p, iObj) ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, pName ); - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Bac_ObjName(p, iObj) ? Bac_ObjNameStr(p, iObj) : "" ); - Vec_StrPrintStr( vStr, " (" ); - // write inputs - Bac_BoxForEachBiMain( 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[iSig] ); - Vec_StrPrintStr( vStr, "(" ); - Bac_ManWriteConcat( p, iTerm, Range ); - Vec_StrPrintStr( vStr, ")" ); - iSig++; - } - Bac_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[iSig] ); - Vec_StrPrintStr( vStr, "(" ); - Bac_ManWriteConcat( p, iTerm, Range ); - Vec_StrPrintStr( vStr, ")" ); - iSig++; - } - assert( iSig == Vec_IntSize(vBits) ); - } - Vec_StrPrintStr( vStr, ");\n" ); - } -} -void Bac_ManWriteVerilogNtk( Bac_Ntk_t * p, int fUseAssign ) -{ - char * pKeyword[4] = { "wire ", "input ", "output ", "inout " }; - Vec_Str_t * vStr = p->pDesign->vOut; - int k, iObj, iTerm, Value, Beg, End, Length, fHaveWires, StartPos; -// assert( Bac_NtkInfoNum(p) ); - assert( Vec_IntSize(&p->vFanin) == Bac_NtkObjNum(p) ); -// Bac_NtkPrint( p ); - // write header - Vec_StrPrintStr( vStr, "module " ); - Vec_StrPrintStr( vStr, Bac_NtkName(p) ); - Vec_StrPrintStr( vStr, " (\n " ); - StartPos = Vec_StrSize(vStr); - Vec_IntForEachEntryTriple( &p->vInfo, Value, Beg, End, k ) - if ( Abc_Lit2Att2(Value) != 0 ) - { - Vec_StrPrintStr( vStr, k ? ", " : "" ); - if ( Vec_StrSize(vStr) > StartPos + 70 ) - { - StartPos = Vec_StrSize(vStr); - Vec_StrPrintStr( vStr, "\n " ); - } - Bac_ManWriteVar( p, Abc_Lit2Var2(Value) ); - } - Vec_StrPrintStr( vStr, "\n );\n" ); - // write inputs/outputs - Vec_IntForEachEntryTriple( &p->vInfo, Value, Beg, End, k ) - if ( Abc_Lit2Att2(Value) != 0 ) - { - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, pKeyword[Abc_Lit2Att2(Value)] ); - if ( Beg >= 0 ) - Bac_ManWriteRange( p, Beg, End ); - Bac_ManWriteVar( p, Abc_Lit2Var2(Value) ); - Vec_StrPrintStr( vStr, ";\n" ); - } - Vec_StrPrintStr( vStr, "\n" ); - // write word-level wires - Bac_NtkForEachBox( p, iObj ) - if ( !Bac_ObjIsConst(p, iObj) ) - Bac_BoxForEachBo( p, iObj, iTerm, k ) - if ( Bac_ObjNameType(p, iTerm) == BAC_NAME_WORD || Bac_ObjNameType(p, iTerm) == BAC_NAME_INFO ) - { - Vec_StrPrintStr( vStr, " wire " ); - Bac_ManWriteRange( p, Bac_ManFindRealIndex(p, iTerm), Bac_ManFindRealIndex(p, iTerm + Bac_ObjGetRange(p, iTerm) - 1) ); - Bac_ManWriteVar( p, Bac_ManFindRealNameId(p, iTerm) ); - Vec_StrPrintStr( vStr, ";\n" ); - } - // check if there are any wires left - fHaveWires = 0; - Bac_NtkForEachBox( p, iObj ) - if ( !Bac_ObjIsConst(p, iObj) ) - Bac_BoxForEachBo( p, iObj, iTerm, k ) - if ( Bac_ObjNameType(p, iTerm) == BAC_NAME_BIN ) - { fHaveWires = 1; iObj = Bac_NtkObjNum(p); break; } - // write bit-level wires - if ( fHaveWires ) - { - Length = 7; - Vec_StrPrintStr( vStr, "\n wire " ); - Bac_NtkForEachBox( p, iObj ) - if ( !Bac_ObjIsConst(p, iObj) ) - Bac_BoxForEachBo( p, iObj, iTerm, k ) - if ( Bac_ObjNameType(p, iTerm) == BAC_NAME_BIN ) - { - if ( Length > 72 ) - Vec_StrPrintStr( vStr, ";\n wire " ), Length = 7; - if ( Length > 7 ) - Vec_StrPrintStr( vStr, ", " ); - Vec_StrPrintStr( vStr, Bac_ObjNameStr(p, iTerm) ); - Length += strlen(Bac_ObjNameStr(p, iTerm)); - } - Vec_StrPrintStr( vStr, ";\n" ); - } - Vec_StrPrintStr( vStr, "\n" ); - // write objects - Bac_ManWriteVerilogBoxes( p, fUseAssign ); - Vec_StrPrintStr( vStr, "endmodule\n\n" ); -} -void Bac_ManWriteVerilog( char * pFileName, Bac_Man_t * p, int fUseAssign ) -{ - Bac_Ntk_t * pNtk; int i; - // check the library - if ( p->pMioLib && p->pMioLib != Abc_FrameReadLibGen() ) - { - printf( "Genlib library used in the mapped design is not longer a current library.\n" ); - return; - } - // derive the stream - p->vOut = Vec_StrAlloc( 10000 ); - p->vOut2 = Vec_StrAlloc( 1000 ); - Vec_StrPrintStr( p->vOut, "// Design \"" ); - Vec_StrPrintStr( p->vOut, Bac_ManName(p) ); - Vec_StrPrintStr( p->vOut, "\" written via CBA package in ABC on " ); - Vec_StrPrintStr( p->vOut, Extra_TimeStamp() ); - Vec_StrPrintStr( p->vOut, "\n\n" ); - Bac_ManAssignInternWordNames( p ); - Bac_ManForEachNtk( p, pNtk, i ) - Bac_ManWriteVerilogNtk( pNtk, fUseAssign ); - // dump into file - if ( p->vOut && Vec_StrSize(p->vOut) > 0 ) - { - FILE * pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - printf( "Cannot open file \"%s\" for writing.\n", pFileName ); - else - { - fwrite( Vec_StrArray(p->vOut), 1, Vec_StrSize(p->vOut), pFile ); - fclose( pFile ); - } - } - Vec_StrFreeP( &p->vOut ); - Vec_StrFreeP( &p->vOut2 ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/bac/module.make b/src/base/bac/module.make deleted file mode 100644 index c0b81045c..000000000 --- a/src/base/bac/module.make +++ /dev/null @@ -1,15 +0,0 @@ -SRC += src/base/bac/bacBlast.c \ - src/base/bac/bacBac.c \ - src/base/bac/bacCom.c \ - src/base/bac/bacLib.c \ - src/base/bac/bacNtk.c \ - src/base/bac/bacPrsBuild.c \ - src/base/bac/bacPrsTrans.c \ - src/base/bac/bacPtr.c \ - src/base/bac/bacPtrAbc.c \ - src/base/bac/bacReadBlif.c \ - src/base/bac/bacReadSmt.c \ - src/base/bac/bacReadVer.c \ - src/base/bac/bacWriteBlif.c \ - src/base/bac/bacWriteSmt.c \ - src/base/bac/bacWriteVer.c diff --git a/src/base/cba/cba.c b/src/base/cba/cba.c deleted file mode 100644 index e825f0528..000000000 --- a/src/base/cba/cba.c +++ /dev/null @@ -1,52 +0,0 @@ -/**CFile**************************************************************** - - FileName [cba.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - Revision [$Id: cba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cba.h b/src/base/cba/cba.h deleted file mode 100644 index adf12a451..000000000 --- a/src/base/cba/cba.h +++ /dev/null @@ -1,1024 +0,0 @@ -/**CFile**************************************************************** - - FileName [cba.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - Revision [$Id: cba.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef ABC__base__cba__cba_h -#define ABC__base__cba__cba_h - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include "aig/gia/gia.h" -#include "misc/extra/extra.h" -#include "misc/util/utilNam.h" -#include "misc/vec/vecHash.h" -#include "cbaTypes.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - - -typedef struct Cba_Ntk_t_ Cba_Ntk_t; -typedef struct Cba_Man_t_ Cba_Man_t; - -// network -struct Cba_Ntk_t_ -{ - Cba_Man_t * pDesign; // design - int Id; // network ID - int NameId; // name ID - int iCopy; // copy module - unsigned Mark : 1; // visit mark - unsigned fComb: 1; // the network is combinational - unsigned fSeq : 1; // the network is sequential - // interface - Vec_Int_t vInputs; // inputs - Vec_Int_t vOutputs; // outputs - Vec_Int_t vOrder; // order - Vec_Int_t vSeq; // sequential objects - // stucture - Vec_Str_t vObjType; // type - Vec_Int_t vObjFin0; // fanins - Vec_Int_t vObjFon0; // outputs - Vec_Int_t vFinFon; // fons - Vec_Int_t vFonObj; // object - // optional - Vec_Int_t vObjCopy; // copy - Vec_Int_t vObjFunc; // function - Vec_Int_t vObjName; // name - Vec_Int_t vObjAttr; // attribute offset - Vec_Int_t vAttrSto; // attribute storage - Vec_Int_t vFonCopy; // copy - Vec_Int_t vFonName; // name - Vec_Int_t vFonRange;// range - Vec_Int_t vFonPrev; // fanout: prev fon - Vec_Int_t vFonNext; // fanout: next fon - Vec_Int_t vFinFon0; // fanout: first fon - Vec_Int_t vFinObj; // object - Vec_Int_t vNtkObjs; // instances - Vec_Int_t vFonBits; // fon mapping into AIG nodes - // other - Vec_Ptr_t * vOther; // various data - Vec_Int_t vArray0; - Vec_Int_t vArray1; -}; - -// design -struct Cba_Man_t_ -{ - // design names - char * pName; // design name - char * pSpec; // spec file name - Abc_Nam_t * pStrs; // string manager - Abc_Nam_t * pFuns; // constant manager - Abc_Nam_t * pMods; // module name manager - Hash_IntMan_t * vHash; // variable ranges - 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]; - int nObjs[CBA_BOX_LAST]; // counter of objects of each type - int nAnds[CBA_BOX_LAST]; // counter of AND gates after blasting - // 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; -}; - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; } -static inline char * Cba_ManSpec( Cba_Man_t * p ) { return p->pSpec; } -static inline int Cba_ManNtkNum( Cba_Man_t * p ) { return Vec_PtrSize(&p->vNtks)-1; } -static inline int Cba_ManNtkIsOk( Cba_Man_t * p, int i ) { return i > 0 && i <= Cba_ManNtkNum(p); } -static inline Cba_Ntk_t * Cba_ManNtk( Cba_Man_t * p, int i ) { return Cba_ManNtkIsOk(p, i) ? (Cba_Ntk_t *)Vec_PtrEntry(&p->vNtks, i) : NULL; } -static inline int Cba_ManNtkFindId( Cba_Man_t * p, char * pName ) { return Abc_NamStrFind(p->pMods, pName); } -static inline Cba_Ntk_t * Cba_ManNtkFind( Cba_Man_t * p, char * pName ) { return Cba_ManNtk( p, Cba_ManNtkFindId(p, pName) ); } -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 int Cba_ManNameIdMax( Cba_Man_t * p ) { return Abc_NamObjNumMax(p->pStrs) + 1; } -static inline char * Cba_ManConst( Cba_Man_t * p, int i ) { return Abc_NamStr(p->pFuns, i); } -static inline int Cba_ManConstId( Cba_Man_t * p, char * pStr ) { return Abc_NamStrFind(p->pFuns, pStr); } -static inline int Cba_ManConstIdMax( Cba_Man_t * p ) { return Abc_NamObjNumMax(p->pFuns) + 1; } - -static inline Cba_Man_t * Cba_NtkMan( Cba_Ntk_t * p ) { return p->pDesign; } -static inline Cba_Ntk_t * Cba_NtkNtk( Cba_Ntk_t * p, int i ) { return Cba_ManNtk(p->pDesign, i); } -static inline int Cba_NtkId( Cba_Ntk_t * p ) { return p->Id; } -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); } -static inline int Cba_NtkPioOrder( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vOrder, i); } -static inline int Cba_NtkBoxSeq( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vSeq, i); } -static inline Abc_Nam_t * Cba_NtkNam( Cba_Ntk_t * p ) { return p->pDesign->pStrs; } -static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Cba_ManStr(p->pDesign, i); } -static inline int Cba_NtkStrId( Cba_Ntk_t * p, char * pName ) { return Cba_ManStrId(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]; } -static inline int Cba_NtkCopy( Cba_Ntk_t * p ) { return p->iCopy; } -static inline Cba_Ntk_t * Cba_NtkCopyNtk(Cba_Man_t * pNew, Cba_Ntk_t * p) { return Cba_ManNtk(pNew, Cba_NtkCopy(p)); } -static inline void Cba_NtkSetCopy( Cba_Ntk_t * p, int i ) { assert(p->iCopy == 0); p->iCopy = i; } -static inline int Cba_NtkHashRange( Cba_Ntk_t * p, int l, int r ) { return Hash_Int2ManInsert( p->pDesign->vHash, l, r, 0 ); } -static inline int Cba_NtkRangeLeft( Cba_Ntk_t * p, int h ) { return h ? Hash_IntObjData0( p->pDesign->vHash, h ) : 0; } -static inline int Cba_NtkRangeRight( Cba_Ntk_t * p, int h ) { return h ? Hash_IntObjData1( p->pDesign->vHash, h ) : 0; } -static inline int Cba_NtkRangeSize( Cba_Ntk_t * p, int h ) { int l = Cba_NtkRangeLeft(p, h), r = Cba_NtkRangeRight(p, h); return 1 + (l > r ? l-r : r-l);} - -static inline int Cba_NtkPiNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); } -static inline int Cba_NtkPoNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); } -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_NtkPioOrderNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vOrder); } -static inline int Cba_NtkObjNum( Cba_Ntk_t * p ) { return Vec_StrSize(&p->vObjType)-1; } -static inline int Cba_NtkObjNumAlloc( Cba_Ntk_t * p ) { return Vec_StrCap(&p->vObjType)-1; } -static inline int Cba_NtkFinNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFinFon)-1; } -static inline int Cba_NtkFinNumAlloc( Cba_Ntk_t * p ) { return Vec_IntCap(&p->vFinFon)-1; } -static inline int Cba_NtkFonNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonObj)-1; } -static inline int Cba_NtkFonNumAlloc( Cba_Ntk_t * p ) { return Vec_IntCap(&p->vFonObj)-1; } -static inline int Cba_NtkTypeNum( Cba_Ntk_t * p, int Type ) { return Vec_StrCountEntry(&p->vObjType, (char)Type); } -static inline int Cba_NtkBoxNum( Cba_Ntk_t * p ) { return Cba_NtkObjNum(p) - Cba_NtkPioNum(p); } -static inline int Cba_NtkBoxUserNum( Cba_Ntk_t * p ) { return Cba_NtkTypeNum(p, CBA_OBJ_BOX); } -static inline int Cba_NtkBoxPrimNum( Cba_Ntk_t * p ) { return Vec_StrCountLarger(&p->vObjType, (char)CBA_OBJ_BOX); } -static inline int Cba_NtkBoxSeqNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vSeq); } - -static inline void Cba_NtkCleanObjCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjCopy, Vec_StrCap(&p->vObjType), -1); } -static inline void Cba_NtkCleanObjFuncs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjFunc, Vec_StrCap(&p->vObjType), 0); } -static inline void Cba_NtkCleanObjNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjName, Vec_StrCap(&p->vObjType), 0); } -static inline void Cba_NtkCleanObjAttrs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjAttr, Vec_StrCap(&p->vObjType), 0); Vec_IntFill(&p->vAttrSto, 1, -1); } -static inline void Cba_NtkCleanFonCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonCopy, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkCleanFonNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonName, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkCleanFonRanges( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonRange, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkCleanFonPrevs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonPrev, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkCleanFonNexts( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonNext, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkCleanFinFon0( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinFon0, Vec_IntCap(&p->vFinFon), 0); } -static inline void Cba_NtkCleanFinObjs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinObj, Vec_IntCap(&p->vFinFon), 0); } - -static inline int Cba_NtkHasObjCopies( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjCopy) > 0; } -static inline int Cba_NtkHasObjFuncs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjFunc) > 0; } -static inline int Cba_NtkHasObjNames( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjName) > 0; } -static inline int Cba_NtkHasObjAttrs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjAttr) > 0; } -static inline int Cba_NtkHasFonCopies( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonCopy) > 0; } -static inline int Cba_NtkHasFonNames( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonName) > 0; } -static inline int Cba_NtkHasFonRanges( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonRange) > 0; } -static inline int Cba_NtkHasFonPrevs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonPrev) > 0; } -static inline int Cba_NtkHasFonNexts( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFonNext) > 0; } -static inline int Cba_NtkHasFinFon0( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFinFon0) > 0; } -static inline int Cba_NtkHasFinObjs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFinObj) > 0; } - -static inline void Cba_NtkFreeObjCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjCopy); } -static inline void Cba_NtkFreeObjFuncs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjFunc); } -static inline void Cba_NtkFreeObjNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjName); } -static inline void Cba_NtkFreeObjAttrs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjAttr); } -static inline void Cba_NtkFreeFonCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonCopy); } -static inline void Cba_NtkFreeFonNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonName); } -static inline void Cba_NtkFreeFonRanges( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonRange); } -static inline void Cba_NtkFreeFonPrevs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonPrev); } -static inline void Cba_NtkFreeFonNexts( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonNext); } -static inline void Cba_NtkFreeFinFon0( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinFon0); } -static inline void Cba_NtkFreeFinObjs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinObj); } - -static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { assert(i>0); return (Cba_ObjType_t)(int)(unsigned char)Vec_StrEntry(&p->vObjType, i); } -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_SQRT || 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; } -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); } -static inline int Cba_ObjIsBox( Cba_Ntk_t * p, int i ) { return Cba_TypeIsBox(Cba_ObjType(p, i)); } -static inline int Cba_ObjIsBoxUser( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_BOX; } -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_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); } -static inline int Cba_ObjFon0( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntry(&p->vObjFon0, i); } -static inline int Cba_ObjFin( Cba_Ntk_t * p, int i, int k ) { assert(i>0); return Cba_ObjFin0(p, i) + k; } -static inline int Cba_ObjFon( Cba_Ntk_t * p, int i, int k ) { assert(i>0); return Cba_ObjFon0(p, i) + k; } -static inline int Cba_ObjFinNum( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_ObjFin0(p, i+1) - Cba_ObjFin0(p, i); } -static inline int Cba_ObjFonNum( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_ObjFon0(p, i+1) - Cba_ObjFon0(p, i); } - -static inline int Cba_ObjCopy( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjCopies(p) ); return Vec_IntGetEntryFull(&p->vObjCopy, i); } -static inline int Cba_ObjFunc( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjFuncs(p) ); return Vec_IntGetEntry(&p->vObjFunc, i); } -static inline int Cba_ObjName( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjNames(p) ); return Vec_IntGetEntry(&p->vObjName, i); } -static inline char * Cba_ObjNameStr( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_NtkStr(p, Cba_ObjName(p, i)); } -static inline int Cba_ObjAttr( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_NtkHasObjAttrs(p) ? Vec_IntGetEntry(&p->vObjAttr, i) : 0; } -static inline int Cba_ObjAttrSize( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_ObjAttr(p, i) ? Vec_IntEntry(&p->vAttrSto, Cba_ObjAttr(p, i)) : 0; } -static inline int * Cba_ObjAttrArray( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_ObjAttr(p, i) ? Vec_IntEntryP(&p->vAttrSto, Cba_ObjAttr(p, i)+1) : NULL; } -static inline int Cba_ObjAttrValue( Cba_Ntk_t * p, int i, int x ) { int k, s = Cba_ObjAttrSize(p, i), * a = Cba_ObjAttrArray(p, i); for ( k = 0; k < s; k += 2) if (a[k] == x) return a[k+1]; return 0; } - -static inline void Cba_ObjSetCopy( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjCopy(p, i) == -1); Vec_IntSetEntry( &p->vObjCopy, i, x ); } -static inline void Cba_ObjSetFunc( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjFunc(p, i) == 0); Vec_IntSetEntry( &p->vObjFunc, i, x ); } -static inline void Cba_ObjSetName( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjName(p, i) == 0); Vec_IntSetEntry( &p->vObjName, i, x ); } -static inline void Cba_ObjSetAttrs( Cba_Ntk_t * p, int i, int * a, int s ) { assert(Cba_ObjAttr(p, i) == 0); if ( !a ) return; Vec_IntSetEntry(&p->vObjAttr, i, Vec_IntSize(&p->vAttrSto)); Vec_IntPush(&p->vAttrSto, s); Vec_IntPushArray(&p->vAttrSto, a, s); } - -static inline int Cba_FinFon( Cba_Ntk_t * p, int f ) { assert(f>0); return Vec_IntEntry(&p->vFinFon, f); } -static inline void Cba_PatchFinFon( Cba_Ntk_t * p, int f, int x ) { assert(f>0); Vec_IntWriteEntry(&p->vFinFon, f, x); } -static inline int Cba_ObjFinFon( Cba_Ntk_t * p, int i, int k ) { assert(i>0); return Cba_FinFon(p, Cba_ObjFin(p, i, k)); } -static inline int * Cba_ObjFinFons( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntryP(&p->vFinFon, Cba_ObjFin0(p, i)); } - -static inline void Cba_ObjSetFinFon( Cba_Ntk_t * p, int i, int k, int x ) { assert(i>0); assert(Cba_ObjFinFon(p, i, k)== 0); Vec_IntWriteEntry(&p->vFinFon, Cba_ObjFin(p, i, k), x); } -static inline void Cba_ObjCleanFinFon( Cba_Ntk_t * p, int i, int k) { assert(i>0); assert(Cba_ObjFinFon(p, i, k)!= 0); Vec_IntWriteEntry(&p->vFinFon, Cba_ObjFin(p, i, k), 0); } -static inline void Cba_ObjPatchFinFon( Cba_Ntk_t * p, int i, int k, int x){ assert(i>0); Cba_ObjCleanFinFon(p, i, k); Cba_ObjSetFinFon(p, i, k, x); } - -static inline int Cba_ObjNtkId( Cba_Ntk_t * p, int i ) { assert(i>0); return (Cba_ObjIsBoxUser(p, i) && Cba_NtkHasObjFuncs(p)) ? Cba_ObjFunc(p, i) : 0;} -static inline Cba_Ntk_t * Cba_ObjNtk( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_NtkNtk(p, Cba_ObjNtkId(p, i)); } -static inline void Cba_ObjSetNtkId( Cba_Ntk_t * p, int i, int x ) { assert(i>0); assert(Cba_ObjIsBoxUser(p, i)); Cba_ObjSetFunc( p, i, x ); } -static inline int Cba_ObjIsSeq( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_ObjIsBoxUser(p, i) ? Cba_ObjNtk(p, i)->fSeq : Cba_TypeIsSeq(Cba_ObjType(p, i)); } - -static inline int Cba_FonIsReal( int f ) { return f > 0; } -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_FonConstRangeSize( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsConst(f)); return atoi(Cba_NtkConst(p, Cba_FonConst(f))); } -static inline int Cba_FonConstSigned( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsConst(f)); return strchr(Cba_NtkConst(p, Cba_FonConst(f)), 's') != NULL; } - -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_FonRangeId( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_NtkHasFonRanges(p)?Vec_IntGetEntry(&p->vFonRange, f):0;} -static inline int Cba_FonRange( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Abc_Lit2Var( Cba_FonRangeId(p, f) ); } -static inline int Cba_FonLeft( Cba_Ntk_t * p, int f ) { return Cba_NtkRangeLeft(p, Cba_FonRange(p, f)); } -static inline int Cba_FonRight( Cba_Ntk_t * p, int f ) { return Cba_NtkRangeRight(p, Cba_FonRange(p, f)); } -static inline int Cba_FonSigned( Cba_Ntk_t * p, int f ) { return Cba_FonIsConst(f) ? Cba_FonConstSigned(p, f) : Abc_LitIsCompl(Cba_FonRangeId(p, f)); } -static inline int Cba_FonRangeSize( Cba_Ntk_t * p, int f ) { return Cba_FonIsConst(f) ? Cba_FonConstRangeSize(p, f):Cba_NtkRangeSize(p, Cba_FonRange(p, f)); } -static inline void Cba_FonSetRangeSign( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonRanges(p)); Vec_IntSetEntry(&p->vFonRange, f, x); } -static inline void Cba_FonSetRange( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonRanges(p)); Vec_IntSetEntry(&p->vFonRange, f, Abc_Var2Lit(x,0)); } -static inline void Cba_FonHashRange( Cba_Ntk_t * p, int f, int l, int r ) { Cba_FonSetRange( p, f, Cba_NtkHashRange(p, l, r) ); } -static inline int Cba_FonCopy( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry(&p->vFonCopy, f) : f; } -static inline void Cba_FonSetCopy( Cba_Ntk_t * p, int f, int x ) { assert(Cba_FonIsReal(f)); assert(Cba_FonCopy(p, f) == 0); Vec_IntWriteEntry(&p->vFonCopy, f, x); } -static inline int Cba_FonName( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); return Vec_IntGetEntry( &p->vFonName, f ); } -static inline char * Cba_FonNameStr( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); return Cba_NtkStr(p, Cba_FonName(p, f)); } -static inline void Cba_FonSetName( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) == 0); Vec_IntSetEntry(&p->vFonName, f, x); } -static inline void Cba_FonCleanName( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) != 0); Vec_IntSetEntry(&p->vFonName, f, 0); } -static inline void Cba_FonPatchName( Cba_Ntk_t * p, int f, int x) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); Cba_FonCleanName(p, f); Cba_FonSetName(p, f, x); } -static inline int Cba_FonIndex( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return f - Cba_ObjFon0( p, Cba_FonObj(p, f) ); } -static inline int Cba_FonNtkId( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_ObjNtkId( p, Cba_FonObj(p, f) ); } -static inline Cba_Ntk_t * Cba_FonNtk( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_ObjNtk( p, Cba_FonObj(p, f) ); } - -static inline int Cba_ObjFanin( Cba_Ntk_t * p, int i, int k ) { assert(i>0); return Cba_FonObj( p, Cba_ObjFinFon(p, i, k) ); } -static inline int Cba_ObjLeft( Cba_Ntk_t * p, int i ) { return Cba_FonLeft( p, Cba_ObjFon0(p, i) ); } -static inline int Cba_ObjRight( Cba_Ntk_t * p, int i ) { return Cba_FonRight( p, Cba_ObjFon0(p, i) ); } -static inline int Cba_ObjRangeSize( Cba_Ntk_t * p, int i ) { return Cba_FonRangeSize( p, Cba_ObjFon0(p, i) ); } -static inline int Cba_ObjSigned( Cba_Ntk_t * p, int i ) { return Cba_FonSigned( p, Cba_ObjFon0(p, i) ); } -static inline int Cba_ObjSign( Cba_Ntk_t * p, int i ) { return Abc_Var2Lit( Cba_FonRangeSize(p, i), Cba_ObjSigned(p, i) ); } - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -#define Cba_ManForEachNtk( p, pNtk, i ) \ - for ( i = 1; (i <= Cba_ManNtkNum(p)) && (((pNtk) = Cba_ManNtk(p, i)), 1); i++ ) - -#define Cba_NtkForEachPi( p, iObj, i ) \ - 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_NtkForEachBoxSeq( p, iObj, i ) \ - for ( i = 0; (i < Cba_NtkBoxSeqNum(p)) && (((iObj) = Cba_NtkBoxSeq(p, i)), 1); i++ ) -#define Cba_NtkForEachPioOrder( p, iObj, i ) \ - for ( i = 0; (i < Cba_NtkPioOrderNum(p)) && (((iObj) = Cba_NtkPioOrder(p, i)), 1); i++ ) - -#define Cba_NtkForEachPiFon( p, iObj, iFon, i ) \ - for ( i = 0; (i < Cba_NtkPiNum(p)) && (((iObj) = Cba_NtkPi(p, i)), 1) && (((iFon) = Cba_ObjFon0(p, iObj)), 1); i++ ) -#define Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) \ - for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Cba_NtkPo(p, i)), 1) && (((iFon) = Cba_ObjFinFon(p, iObj, 0)), 1); i++ ) -#define Cba_NtkForEachPoDriver( p, iObj, i ) \ - for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Cba_ObjFanin(p, Cba_NtkPo(p, i), 0)), 1); i++ ) - -#define Cba_NtkForEachObj( p, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjType(p, i) ) {} else -#define Cba_NtkForEachObjType( p, Type, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType) && (((Type) = Cba_ObjType(p, i)), 1); i++ ) if ( !Type ) {} else -#define Cba_NtkForEachBox( p, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjIsBox(p, i) ) {} else -#define Cba_NtkForEachBoxComb( p, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjIsBox(p, i) || Cba_ObjIsSeq(p, i) ) {} else -#define Cba_NtkForEachBoxUser( p, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjIsBoxUser(p, i) ) {} else -#define Cba_NtkForEachBoxPrim( p, i ) \ - for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjIsBoxPrim(p, i) ) {} else - -#define Cba_NtkForEachFon( p, i ) \ - for ( i = 1; i < Vec_IntSize(&p->vFonObj); i++ ) -#define Cba_NtkForEachFinFon( p, iFon, iFin ) \ - for ( iFin = 1; iFin < Vec_IntSize(&p->vFinFon) && (((iFon) = Vec_IntEntry(&p->vFinFon, iFin)), 1); iFin++ ) if ( !iFon ) {} else -#define Cba_NtkForEachFonName( p, NameId, iFon ) \ - for ( iFon = 1; iFon < Vec_IntSize(&p->vFonName) && (((NameId) = Vec_IntEntry(&p->vFonName, iFon)), 1); iFon++ ) if ( !NameId ) {} else - -#define Cba_ObjForEachFin( p, iObj, iFin, k ) \ - for ( k = 0, iFin = Cba_ObjFin0(p, iObj); iFin < Cba_ObjFin0(p, iObj+1); iFin++, k++ ) -#define Cba_ObjForEachFon( p, iObj, iFon, k ) \ - for ( k = 0, iFon = Cba_ObjFon0(p, iObj); iFon < Cba_ObjFon0(p, iObj+1); iFon++, k++ ) -#define Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) \ - for ( k = 0, iFin = Cba_ObjFin0(p, iObj); iFin < Cba_ObjFin0(p, iObj+1) && ((iFon = Cba_FinFon(p, iFin)), 1); iFin++, k++ ) -#define Cba_ObjForEachFinFanin( p, iObj, iFin, iFanin, k ) \ - for ( k = 0, iFin = Cba_ObjFin0(p, iObj); iFin < Cba_ObjFin0(p, iObj+1) && ((iFanin = Cba_FonObj(p, Cba_FinFon(p, iFin))), 1); iFin++, k++ ) -#define Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) \ - for ( k = 0, iFin = Cba_ObjFin0(p, iObj); iFin < Cba_ObjFin0(p, iObj+1) && ((iFanin = Cba_FonObj(p, Cba_FinFon(p, iFin))), 1); iFin++, k++ ) if ( !iFanin ) {} else - - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Object APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Cba_ObjAlloc( Cba_Ntk_t * p, Cba_ObjType_t Type, int nFins, int nFons ) -{ - int i, iObj = Vec_StrSize(&p->vObjType); - if ( Type == CBA_OBJ_PI ) - Vec_IntPush( &p->vInputs, iObj ); - else if ( Type == CBA_OBJ_PO ) - Vec_IntPush( &p->vOutputs, iObj ); - Vec_StrPush( &p->vObjType, (char)Type ); - // add fins - for ( i = 0; i < nFins; i++ ) - Vec_IntPush( &p->vFinFon, 0 ); - if ( Vec_IntSize(&p->vObjFin0) ) - Vec_IntPush( &p->vObjFin0, Vec_IntSize(&p->vFinFon) ); - // add fons - for ( i = 0; i < nFons; i++ ) - Vec_IntPush( &p->vFonObj, iObj ); - if ( Vec_IntSize(&p->vObjFon0) ) - Vec_IntPush( &p->vObjFon0, Vec_IntSize(&p->vFonObj) ); - return iObj; -} -static inline int Cba_ObjDup( Cba_Ntk_t * pNew, Cba_Ntk_t * p, int i ) -{ - int iObj = Cba_ObjAlloc( pNew, Cba_ObjType(p, i), Cba_ObjFinNum(p, i), Cba_ObjFonNum(p, i) ); - Cba_ObjSetCopy( p, i, iObj ); - return iObj; -} -static inline void Cba_ObjDelete( Cba_Ntk_t * p, int i ) -{ - int k, iFin, iFon; - Cba_ObjCleanType( p, i ); - Cba_ObjForEachFin( p, i, iFin, k ) - Vec_IntWriteEntry( &p->vFinFon, iFin, 0 ); - Cba_ObjForEachFon( p, i, iFon, k ) - Vec_IntWriteEntry( &p->vFonObj, iFon, 0 ); -} - -/**Function************************************************************* - - Synopsis [Network APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, int NameId, int nIns, int nOuts, int nObjs, int nFins, int nFons ) -{ - Cba_Ntk_t * pNew = ABC_CALLOC( Cba_Ntk_t, 1 ); - assert( nIns >= 0 && nOuts >= 0 && nObjs >= 0 && nFins >= 0 && nFons >= 0 ); - pNew->Id = Vec_PtrSize(&p->vNtks); Vec_PtrPush( &p->vNtks, pNew ); - pNew->NameId = NameId; - pNew->pDesign = p; - Vec_IntGrow( &pNew->vInputs, nIns ); - Vec_IntGrow( &pNew->vOutputs, nOuts ); - Vec_StrGrow( &pNew->vObjType, nObjs+1 ); Vec_StrPush( &pNew->vObjType, (char)CBA_OBJ_NONE ); - Vec_IntGrow( &pNew->vObjFin0, nObjs+2 ); Vec_IntPush( &pNew->vObjFin0, 0 ); Vec_IntPush( &pNew->vObjFin0, 1 ); - Vec_IntGrow( &pNew->vObjFon0, nObjs+2 ); Vec_IntPush( &pNew->vObjFon0, 0 ); Vec_IntPush( &pNew->vObjFon0, 1 ); - Vec_IntGrow( &pNew->vFinFon, nFins+1 ); Vec_IntPush( &pNew->vFinFon, 0 ); - Vec_IntGrow( &pNew->vFonObj, nFons+1 ); Vec_IntPush( &pNew->vFonObj, 0 ); - return pNew; -} -static inline void Cba_NtkFree( Cba_Ntk_t * p ) -{ - // interface - Vec_IntErase( &p->vInputs ); - Vec_IntErase( &p->vOutputs ); - Vec_IntErase( &p->vOrder ); - Vec_IntErase( &p->vSeq ); - // stucture - Vec_StrErase( &p->vObjType ); - Vec_IntErase( &p->vObjFin0 ); - Vec_IntErase( &p->vObjFon0 ); - Vec_IntErase( &p->vFinFon ); - Vec_IntErase( &p->vFonObj ); - // optional - Vec_IntErase( &p->vObjCopy ); - Vec_IntErase( &p->vObjFunc ); - Vec_IntErase( &p->vObjName ); - Vec_IntErase( &p->vObjAttr ); - Vec_IntErase( &p->vAttrSto ); - Vec_IntErase( &p->vFonCopy ); - Vec_IntErase( &p->vFonName ); - Vec_IntErase( &p->vFonRange ); - Vec_IntErase( &p->vFonPrev ); - Vec_IntErase( &p->vFonNext ); - Vec_IntErase( &p->vFinFon0 ); - Vec_IntErase( &p->vFinObj ); - Vec_IntErase( &p->vNtkObjs ); - Vec_IntErase( &p->vFonBits ); - // other - Vec_IntErase( &p->vArray0 ); - Vec_IntErase( &p->vArray1 ); - if ( p->vOther ) Vec_VecFree( (Vec_Vec_t *)p->vOther ); - ABC_FREE( p ); -} -static inline int Cba_NtkNewStrId( Cba_Ntk_t * pNtk, const char * format, ... ) -{ - Abc_Nam_t * p = Cba_NtkNam( pNtk ); - Vec_Str_t * vBuf = Abc_NamBuffer( p ); - int nAdded, nSize = 1000; - va_list args; va_start( args, format ); - Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nSize ); - nAdded = vsnprintf( Vec_StrLimit(vBuf), nSize, format, args ); - if ( nAdded > nSize ) - { - Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nAdded + nSize ); - nSize = vsnprintf( Vec_StrLimit(vBuf), nAdded, format, args ); - assert( nSize == nAdded ); - } - va_end( args ); - return Abc_NamStrFindOrAddLim( p, Vec_StrLimit(vBuf), Vec_StrLimit(vBuf) + nAdded, NULL ); -} -static inline int Cba_ManNewConstId( Cba_Ntk_t * p, Vec_Str_t * vBits ) -{ - Vec_Str_t * vOut = Abc_NamBuffer(Cba_NtkNam(p)); - Vec_StrPrintF( vOut, "%d\'b%s", Vec_StrSize(vBits)-1, Vec_StrArray(vBits) ); - return Abc_NamStrFindOrAdd(p->pDesign->pFuns, Vec_StrArray(vOut), NULL); -} -static inline int Cba_ManNewConstZero( Cba_Ntk_t * p, int nBits ) -{ - Vec_Str_t * vOut = Abc_NamBuffer(Cba_NtkNam(p)); - Vec_StrPrintF( vOut, "%d\'b%0s", nBits, "" ); - return Abc_NamStrFindOrAdd(p->pDesign->pFuns, Vec_StrArray(vOut), NULL); -} -static inline void Cba_NtkAdd( Cba_Man_t * p, Cba_Ntk_t * pNtk ) -{ - int fFound, NtkId = Abc_NamStrFindOrAdd( p->pMods, Cba_NtkName(pNtk), &fFound ); - if ( fFound ) - printf( "Network with name \"%s\" already exists.\n", Cba_NtkName(pNtk) ); - else - assert( NtkId == pNtk->Id ); -} -static inline void Cba_NtkUpdate( Cba_Man_t * p, Cba_Ntk_t * pNtk ) -{ - int fFound, NtkId = Abc_NamStrFindOrAdd( p->pMods, Cba_NtkName(pNtk), &fFound ); - if ( !fFound ) - printf( "Network with name \"%s\" does not exist.\n", Cba_NtkName(pNtk) ); - else - { - Cba_NtkFree( Cba_ManNtk(p, NtkId) ); - Vec_PtrWriteEntry( &p->vNtks, NtkId, pNtk ); - } -} -static inline Vec_Int_t * Cba_NtkCollect( Cba_Ntk_t * p ) -{ - int iObj; - Vec_Int_t * vObjs = Vec_IntAlloc( Cba_NtkObjNum(p) ); - Cba_NtkForEachObj( p, iObj ) - Vec_IntPush( vObjs, iObj ); - return vObjs; -} -static inline int Cba_NtkIsSeq( Cba_Ntk_t * p ) -{ - int iObj; - if ( p->fSeq ) - return 1; - if ( p->fComb ) - return 0; - assert( !p->fSeq && !p->fComb ); - Cba_NtkForEachBox( p, iObj ) - if ( Cba_ObjIsBoxUser(p, iObj) ) - { - if ( Cba_NtkIsSeq( Cba_ObjNtk(p, iObj) ) ) - { - p->fSeq = 1; - return 1; - } - } - else if ( Cba_ObjIsSeq(p, iObj) ) - { - p->fSeq = 1; - return 1; - } - p->fComb = 1; - return 0; -} -static inline void Cba_NtkPrepareSeq( Cba_Ntk_t * p ) -{ - int iObj; - assert( Cba_NtkBoxSeqNum(p) == 0 ); - if ( !Cba_NtkIsSeq(p) ) - return; - Cba_NtkForEachBox( p, iObj ) - if ( Cba_ObjIsSeq(p, iObj) ) - Vec_IntPush( &p->vSeq, iObj ); - // Cba_NtkObjOrder( p, &p->vSeq, NULL ); -} -static inline void Cba_NtkCountParams( Cba_Ntk_t * p, Vec_Int_t * vObjs, int * nPis, int * nPos, int * nFins, int * nFons ) -{ - int i, iObj; - *nPis = *nPos = *nFins = *nFons = 0; - Vec_IntForEachEntry( vObjs, iObj, i ) - { - *nPis += Cba_ObjIsPi(p, iObj); - *nPos += Cba_ObjIsPo(p, iObj); - *nFins += Cba_ObjFinNum(p, iObj); - *nFons += Cba_ObjFonNum(p, iObj); - } -} -static inline Cba_Ntk_t * Cba_NtkDup( Cba_Man_t * pMan, Cba_Ntk_t * p, Vec_Int_t * vObjs ) -{ - Cba_Ntk_t * pNew; - int i, k, iObj, iObjNew, iFin, iFon; - int nPis, nPos, nFins, nFons; - Cba_NtkCountParams( p, vObjs, &nPis, &nPos, &nFins, &nFons ); - pNew = Cba_NtkAlloc( pMan, Cba_NtkNameId(p), nPis, nPos, Vec_IntSize(vObjs), nFins, nFons ); - Cba_NtkCleanObjCopies( p ); - Cba_NtkCleanFonCopies( p ); - Vec_IntForEachEntry( vObjs, iObj, i ) - { - iObjNew = Cba_ObjDup( pNew, p, iObj ); - Cba_ObjForEachFon( p, iObj, iFon, k ) - Cba_FonSetCopy( p, iFon, Cba_ObjFon(pNew, iObjNew, k) ); - } - Vec_IntForEachEntry( vObjs, iObj, i ) - { - iObjNew = Cba_ObjCopy( p, iObj ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - Cba_ObjSetFinFon( pNew, iObjNew, k, Cba_FonCopy(p, iFon) ); - } - //Cba_NtkFreeObjCopies( p ); - //Cba_NtkFreeFonCopies( p ); - assert( Cba_NtkObjNum(pNew) == Cba_NtkObjNumAlloc(pNew) ); - Cba_NtkSetCopy( p, Cba_NtkId(pNew) ); - return pNew; -} -static inline Cba_Ntk_t * Cba_NtkDupOrder( Cba_Man_t * pMan, Cba_Ntk_t * p, Vec_Int_t*(* pFuncOrder)(Cba_Ntk_t*) ) -{ - Cba_Ntk_t * pNew; - Vec_Int_t * vObjs = pFuncOrder ? pFuncOrder(p) : Cba_NtkCollect(p); - if ( vObjs == NULL ) - return NULL; - pNew = Cba_NtkDup( pMan, p, vObjs ); - Vec_IntFree( vObjs ); - //Cba_NtkPrepareSeq( pNew ); - return pNew; -} -static inline void Cba_NtkDupAttrs( Cba_Ntk_t * pNew, Cba_Ntk_t * p ) -{ - int i, iObj; - assert( Vec_IntSize(&pNew->vOrder) == 0 ); - Cba_NtkForEachPioOrder( p, iObj, i ) - Vec_IntPush( &pNew->vOrder, Cba_ObjCopy(p, iObj) ); -// Vec_IntRemapArray( &p->vObjCopy, &p->vOrder, &pNew->vOrder, Cba_NtkPioOrderNum(p) ); -// Vec_IntRemapArray( &p->vObjCopy, &p->vSeq, &pNew->vSeq, Cba_NtkBoxSeqNum(p) ); - // transfer object attributes - Vec_IntRemapArray( &p->vObjCopy, &p->vObjFunc, &pNew->vObjFunc, Cba_NtkObjNum(pNew) + 1 ); - Vec_IntRemapArray( &p->vObjCopy, &p->vObjName, &pNew->vObjName, Cba_NtkObjNum(pNew) + 1 ); - Vec_IntRemapArray( &p->vObjCopy, &p->vObjAttr, &pNew->vObjAttr, Cba_NtkObjNum(pNew) + 1 ); - // transfer fon attributes - Vec_IntRemapArray( &p->vFonCopy, &p->vFonName, &pNew->vFonName, Cba_NtkFonNum(pNew) + 1 ); - Vec_IntRemapArray( &p->vFonCopy, &p->vFonRange, &pNew->vFonRange, Cba_NtkFonNum(pNew) + 1 ); - // duplicate attributes - Vec_IntAppend( &pNew->vAttrSto, &p->vAttrSto ); - pNew->vOther = p->vOther ? (Vec_Ptr_t *)Vec_VecDup( (Vec_Vec_t *)p->vOther ) : NULL; -} -static inline int Cba_NtkMemory( Cba_Ntk_t * p ) -{ - int nMem = sizeof(Cba_Ntk_t); - // interface - nMem += (int)Vec_IntMemory(&p->vInputs); - nMem += (int)Vec_IntMemory(&p->vOutputs); - nMem += (int)Vec_IntMemory(&p->vOrder); - nMem += (int)Vec_IntMemory(&p->vSeq); - // stucture - nMem += (int)Vec_StrMemory(&p->vObjType); - nMem += (int)Vec_IntMemory(&p->vObjFin0); - nMem += (int)Vec_IntMemory(&p->vObjFon0); - nMem += (int)Vec_IntMemory(&p->vFinFon); - nMem += (int)Vec_IntMemory(&p->vFonObj); - // optional - nMem += (int)Vec_IntMemory(&p->vObjCopy ); - nMem += (int)Vec_IntMemory(&p->vObjFunc ); - nMem += (int)Vec_IntMemory(&p->vObjName ); - nMem += (int)Vec_IntMemory(&p->vObjAttr ); - nMem += (int)Vec_IntMemory(&p->vAttrSto ); - nMem += (int)Vec_IntMemory(&p->vFonCopy ); - nMem += (int)Vec_IntMemory(&p->vFonName ); - nMem += (int)Vec_IntMemory(&p->vFonRange ); - nMem += (int)Vec_IntMemory(&p->vFonPrev ); - nMem += (int)Vec_IntMemory(&p->vFonNext ); - nMem += (int)Vec_IntMemory(&p->vFinFon0 ); - nMem += (int)Vec_IntMemory(&p->vFinObj ); - nMem += (int)Vec_IntMemory(&p->vNtkObjs ); - nMem += (int)Vec_IntMemory(&p->vFonBits ); - // other - nMem += (int)Vec_IntMemory(&p->vArray1 ); - nMem += (int)Vec_IntMemory(&p->vArray1 ); - return nMem; -} -static inline void Cba_NtkPrintStats( Cba_Ntk_t * p ) -{ - printf( "pi =%5d ", Cba_NtkPiNum(p) ); - printf( "po =%5d ", Cba_NtkPoNum(p) ); - printf( "seq =%5d ", Cba_NtkBoxSeqNum(p) ); - printf( "box =%5d ", Cba_NtkBoxNum(p) ); - printf( "prim =%5d ", Cba_NtkBoxPrimNum(p) ); - printf( "user =%5d ", Cba_NtkBoxUserNum(p) ); - //printf( "topo =%4s ", Cba_NtkIsTopoOrder(p) ? "yes" : "no" ); - printf( " %s ", Cba_NtkName(p) ); - if ( Vec_IntSize(&p->vNtkObjs) ) - printf( "-> %s", Cba_NtkName(Cba_NtkNtk(p, Vec_IntEntry(&p->vNtkObjs, 0))) ); - printf( "\n" ); -// Vec_StrIntPrint( &p->vObjType ); -} -static inline void Cba_NtkPrint( Cba_Ntk_t * p ) -{ - int i, Type; - printf( "Interface (%d):\n", Cba_NtkPioNum(p) ); - printf( "Objects (%d):\n", Cba_NtkObjNum(p) ); - Cba_NtkForEachObjType( p, Type, i ) - { - printf( "%6d : ", i ); - printf( "Type =%3d ", Type ); - printf( "Fins = %d ", Cba_ObjFinNum(p, i) ); - printf( "Fons = %d ", Cba_ObjFonNum(p, i) ); - if ( Cba_NtkHasObjNames(p) && Cba_ObjName(p, i) ) - printf( "%s", Cba_ObjNameStr(p, i) ); - printf( "\n" ); - } -} - -/**Function************************************************************* - - Synopsis [Manager APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Cba_Man_t * Cba_ManAlloc( char * pFileName, int nNtks, Abc_Nam_t * pStrs, Abc_Nam_t * pFuns, Abc_Nam_t * pMods, Hash_IntMan_t * vHash ) -{ - Cba_Man_t * pNew = ABC_CALLOC( Cba_Man_t, 1 ); - pNew->pName = Extra_FileDesignName( pFileName ); - pNew->pSpec = Abc_UtilStrsav( pFileName ); - pNew->pStrs = pStrs ? pStrs : Abc_NamStart( 1000, 24 ); - pNew->pFuns = pFuns ? pFuns : Abc_NamStart( 100, 24 ); - pNew->pMods = pMods ? pMods : Abc_NamStart( 100, 24 ); - pNew->vHash = vHash ? vHash : Hash_IntManStart( 1000 ); - if ( pFuns == NULL ) - { - Abc_NamStrFindOrAdd(pNew->pFuns, "1\'b0", NULL); - Abc_NamStrFindOrAdd(pNew->pFuns, "1\'b1", NULL); - Abc_NamStrFindOrAdd(pNew->pFuns, "1\'bx", NULL); - Abc_NamStrFindOrAdd(pNew->pFuns, "1\'bz", NULL); - } -// if ( vHash == NULL ) -// Hash_Int2ManInsert( pNew->vHash, 0, 0, 0 ); - Vec_PtrGrow( &pNew->vNtks, nNtks+1 ); Vec_PtrPush( &pNew->vNtks, NULL ); - // set default root module - pNew->iRoot = 1; - return pNew; -} -static inline void Cba_ManDupTypeNames( Cba_Man_t * pNew, Cba_Man_t * p ) -{ - memcpy( pNew->pTypeNames, p->pTypeNames, sizeof(void *) * CBA_BOX_LAST ); -} -static inline Cba_Man_t * Cba_ManDup( Cba_Man_t * p, Vec_Int_t*(* pFuncOrder)(Cba_Ntk_t*) ) -{ - Cba_Ntk_t * pNtk, * pNtkNew; int i; - Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, Cba_ManNtkNum(p), Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24), Hash_IntManRef(p->vHash) ); - Cba_ManDupTypeNames( pNew, p ); - Cba_ManForEachNtk( p, pNtk, i ) - { - pNtkNew = Cba_NtkDupOrder( pNew, pNtk, pFuncOrder ); - Cba_NtkAdd( pNew, pNtkNew ); - Cba_NtkDupAttrs( pNtkNew, pNtk ); - } -// Cba_ManForEachNtk( p, pNtk, i ) -// if ( (pHost = Cba_NtkHostNtk(pNtk)) ) -// Cba_NtkSetHost( Cba_NtkCopyNtk(pNew, pNtk), Cba_NtkCopy(pHost), Cba_ObjCopy(pHost, Cba_NtkHostObj(pNtk)) ); - pNew->iRoot = Cba_ManNtkNum(pNew); - return pNew; -} -static inline void Cba_ManPrepareSeq( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkPrepareSeq( pNtk ); -} -static inline void Cba_ManFree( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkFree( pNtk ); - ABC_FREE( p->vNtks.pArray ); - Abc_NamDeref( p->pStrs ); - Abc_NamDeref( p->pFuns ); - Abc_NamDeref( p->pMods ); - Hash_IntManDeref( p->vHash ); - 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_ManUnsetMap( Cba_Man_t * p, int i ) -{ - Vec_IntSetEntry( &p->vNameMap, i, 0 ); -} -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_NtkUnsetMap( Cba_Ntk_t * p, int i ) { Cba_ManUnsetMap(p->pDesign, i); } -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_ManUnsetMap2( Cba_Man_t * p, int i ) -{ - Vec_IntSetEntry( &p->vNameMap2, i, 0 ); -} -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_NtkUnsetMap2( Cba_Ntk_t * p, int i ) { Cba_ManUnsetMap2(p->pDesign, i); } -static inline void Cba_NtkCleanMap2( Cba_Ntk_t * p ) { Cba_ManCleanMap2(p->pDesign); } - -static inline int Cba_ManMemory( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - int nMem = sizeof(Cba_Man_t); - nMem += p->pName ? (int)strlen(p->pName) : 0; - nMem += p->pSpec ? (int)strlen(p->pSpec) : 0; - nMem += Abc_NamMemUsed(p->pStrs); - nMem += Abc_NamMemUsed(p->pFuns); - 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 ); - return nMem; -} -static inline int Cba_ManObjNum( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i, Count = 0; - Cba_ManForEachNtk( p, pNtk, i ) - Count += Cba_NtkObjNum(pNtk); - return Count; -} -static inline int Cba_ManBoxNum( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i, Count = 0; - Cba_ManForEachNtk( p, pNtk, i ) - Count += Cba_NtkBoxNum( pNtk ); - return Count; -} -static inline void Cba_ManBoxNumRec_rec( Cba_Ntk_t * p, int * pCountP, int * pCountU ) -{ - int iObj, Id = Cba_NtkId(p); - if ( pCountP[Id] >= 0 ) - return; - pCountP[Id] = pCountU[Id] = 0; - Cba_NtkForEachObj( p, iObj ) - { - if ( Cba_ObjIsBoxUser(p, iObj) ) - { - Cba_ManBoxNumRec_rec( Cba_ObjNtk(p, iObj), pCountP, pCountU ); - pCountP[Id] += pCountP[Cba_ObjNtkId(p, iObj)]; - pCountU[Id] += pCountU[Cba_ObjNtkId(p, iObj)] + 1; - } - else - pCountP[Id] += 1; - } -} -static inline void Cba_ManBoxNumRec( Cba_Man_t * p, int * pnPrims, int * pnUsers ) -{ - Cba_Ntk_t * pNtk = Cba_ManRoot(p); - int * pCountP = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); - int * pCountU = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); - Cba_ManBoxNumRec_rec( pNtk, pCountP, pCountU ); - *pnPrims = pCountP[Cba_NtkId(pNtk)]; - *pnUsers = pCountU[Cba_NtkId(pNtk)]; - ABC_FREE( pCountP ); - ABC_FREE( pCountU ); -} -static inline void Cba_ManPrintStats( Cba_Man_t * p, int nModules, int fVerbose ) -{ - Cba_Ntk_t * pNtk; int i, nPrims, nUsers; - Cba_Ntk_t * pRoot = Cba_ManRoot( p ); - Cba_ManBoxNumRec( p, &nPrims, &nUsers ); - printf( "%-12s : ", Cba_ManName(p) ); - printf( "pi =%5d ", Cba_NtkPiNum(pRoot) ); - printf( "po =%5d ", Cba_NtkPoNum(pRoot) ); - printf( "mod =%5d ", Cba_ManNtkNum(p) ); - printf( "box =%5d ", nPrims + nUsers ); - printf( "prim =%5d ", nPrims ); - printf( "user =%5d ", nUsers ); - printf( "mem =%6.3f MB", 1.0*Cba_ManMemory(p)/(1<<20) ); - printf( "\n" ); - Cba_ManForEachNtk( p, pNtk, i ) - { - if ( i == nModules+1 ) - break; - printf( "Module %5d : ", i ); - Cba_NtkPrintStats( pNtk ); - } -} - - -/**Function************************************************************* - - Synopsis [Name handling.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Cba_NtkAddMissingFonNames( Cba_Ntk_t * p, char * pPref ) -{ - int iFon, NameId, Index; - // populate map - Cba_ManCleanMap( p->pDesign ); - Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) - if ( NameId ) - Cba_ManSetMap( p->pDesign, NameId, iFon ); - // check remaining ones - Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) - { - if ( NameId ) - continue; - NameId = Cba_NtkNewStrId(p, "%s%d", pPref, iFon); - for ( Index = 1; Cba_ManGetMap(p->pDesign, NameId); Index++ ) - NameId = Cba_NtkNewStrId(p, "%s%d_%d", pPref, iFon, Index); - Cba_FonSetName( p, iFon, NameId ); - Cba_ManSetMap( p->pDesign, NameId, iFon ); - } -} -static inline void Cba_NtkCreateFonNames( Cba_Ntk_t * p, char * pPref ) -{ - int i, iObj, iFon;//, NameId; - Cba_NtkCleanFonNames( p ); - Cba_NtkForEachPiFon( p, iObj, iFon, i ) - if ( !Cba_FonName(p, iFon) ) - Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); - Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) - if ( Cba_FonIsReal(iFon) && !Cba_FonName(p, iFon) ) - Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); -// Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) -// if ( NameId == 0 ) -// Vec_IntWriteEntry( &p->vFonName, iFon, Cba_NtkNewStrId(p, "%s%d", pPref, iFon) ); - Cba_NtkAddMissingFonNames( p, pPref ); -} -static inline void Cba_NtkMissingFonNames( Cba_Ntk_t * p, char * pPref ) -{ - int i, iObj, iFon;//, NameId; - Cba_NtkForEachPiFon( p, iObj, iFon, i ) - if ( !Cba_FonName(p, iFon) ) - Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); - Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) - if ( Cba_FonIsReal(iFon) && !Cba_FonName(p, iFon) ) - Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); -// Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) -// if ( NameId == 0 ) -// Cba_FonSetName( p, iFon, Cba_NtkNewStrId(p, "%s%d", pPref, iFon) ); - Cba_NtkAddMissingFonNames( p, pPref ); -} - - -/*=== cbaBlast.c =============================================================*/ -extern Gia_Man_t * Cba_ManBlast( Cba_Man_t * p, int fBarBufs, int fSeq, 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_NtkPrintStatsFull( Cba_Ntk_t * p, int fDistrib, int fVerbose ); -extern void Cba_NtkPrintNodes( Cba_Ntk_t * p, int Type ); -extern void Cba_NtkPrintDistribOld( Cba_Ntk_t * p ); -extern void Cba_ManPrintDistrib( Cba_Man_t * p ); -//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 ); -extern int Cba_NtkCheckComboLoop( Cba_Ntk_t * p ); -extern int Cba_ManIsTopoOrder( Cba_Man_t * p ); -extern Vec_Int_t * Cba_NtkCollectDfs( Cba_Ntk_t * p ); -extern Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p ); -extern Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs ); -extern Cba_Man_t * Cba_ManDeriveFromGia( Cba_Man_t * p, Gia_Man_t * pGia, int fUseXor ); -extern Cba_Man_t * Cba_ManInsertGroup( Cba_Man_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ); -/*=== cbaReadBlif.c ==========================================================*/ -extern Cba_Man_t * Prs_ManBuildCbaBlif( char * pFileName, Vec_Ptr_t * vDes ); -extern void Prs_ManReadBlifTest( char * pFileName ); -extern Cba_Man_t * Cba_ManReadBlif( char * pFileName ); -/*=== cbaReadVer.c ===========================================================*/ -extern Cba_Man_t * Prs_ManBuildCbaVerilog( char * pFileName, Vec_Ptr_t * vDes ); -extern void Prs_ManReadVerilogTest( 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 ); -/*=== cbaWriteVer.c ==========================================================*/ -extern void Cba_ManCreatePrimMap( char ** pMap ); -extern char * Cba_ManGetSliceName( Cba_Ntk_t * p, int iFon, int RangeId ); -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 - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/base/cba/cbaBlast.c b/src/base/cba/cbaBlast.c deleted file mode 100644 index 937b9b69a..000000000 --- a/src/base/cba/cbaBlast.c +++ /dev/null @@ -1,1069 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaBlast.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Collapsing word-level design.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - 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 - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Helper functions.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_NtkPrepareBits( Cba_Ntk_t * p ) -{ - int i, nBits = 0; - Cba_NtkCleanFonCopies( p ); - Cba_NtkForEachFon( p, i ) - { - Cba_FonSetCopy( p, i, nBits ); - nBits += Cba_FonRangeSize( p, i ); - } - return nBits; -} -int * Cba_VecCopy( Vec_Int_t * vOut, int * pArray, int nSize ) -{ - int i; Vec_IntClear( vOut ); - for( i = 0; i < nSize; i++) - Vec_IntPush( vOut, pArray[i] ); - return Vec_IntArray( vOut ); -} -int Cba_ReadHexDigit( char HexChar ) -{ - if ( HexChar >= '0' && HexChar <= '9' ) - return HexChar - '0'; - if ( HexChar >= 'A' && HexChar <= 'F' ) - return HexChar - 'A' + 10; - if ( HexChar >= 'a' && HexChar <= 'f' ) - return HexChar - 'a' + 10; - assert( 0 ); // not a hexadecimal symbol - return -1; // return value which makes no sense -} -void Cba_BlastConst( Cba_Ntk_t * p, Vec_Int_t * vOut, int iFon, int nTotal, int fSigned ) -{ - char * pConst = Cba_NtkConst(p, Cba_FonConst(iFon)); - char * pLimit = pConst + strlen(pConst); - int i, Number, nBits = atoi( pConst ); - assert( nBits <= nTotal ); - while ( *pConst >= '0' && *pConst <= '9' ) - pConst++; - assert( *pConst == '\'' ); - pConst++; - if ( *pConst == 's' ) // assume signedness is already used in setting fSigned - pConst++; - Vec_IntClear( vOut ); - if ( *pConst == 'b' ) - { - while ( --pLimit > pConst ) - Vec_IntPush( vOut, *pLimit == '0' ? 0 : 1 ); - } - else if ( *pConst == 'h' ) - { - while ( --pLimit > pConst ) - { - Number = Cba_ReadHexDigit( *pLimit ); - for ( i = 0; i < 4; i++ ) - Vec_IntPush( vOut, (Number >> i) & 1 ); - } - if ( Vec_IntSize(vOut) > nTotal ) - Vec_IntShrink( vOut, nTotal ); - } - else if ( *pConst == 'd' ) - { - Number = atoi( pConst+1 ); - assert( Number <= 0x7FFFFFFF ); - for ( i = 0; i < 32; i++ ) - Vec_IntPush( vOut, (Number >> i) & 1 ); - if ( Vec_IntSize(vOut) > nTotal ) - Vec_IntShrink( vOut, nTotal ); - } - else assert( 0 ); - if ( fSigned && Vec_IntSize(vOut) < nTotal ) - Vec_IntFillExtra( vOut, nTotal - Vec_IntSize(vOut), Vec_IntEntryLast(vOut) ); -} -int * Cba_VecLoadFanins( Cba_Ntk_t * p, Vec_Int_t * vOut, int iFon, int * pFanins, int nFanins, int nTotal, int fSigned ) -{ - assert( nFanins <= nTotal ); - if ( Cba_FonIsReal(iFon) ) - { - int i, Fill = fSigned ? pFanins[nFanins-1] : 0; - Vec_IntClear( vOut ); - for( i = 0; i < nTotal; i++) - Vec_IntPush( vOut, i < nFanins ? pFanins[i] : Fill ); - } - else if ( Cba_FonIsConst(iFon) ) - Cba_BlastConst( p, vOut, iFon, nTotal, fSigned ); - else if ( iFon == 0 ) // undriven input - Vec_IntFill( vOut, nTotal, 0 ); - else assert( 0 ); - assert( Vec_IntSize(vOut) == nTotal ); - return Vec_IntArray( vOut ); -} -int Cba_NtkMuxTree_rec( Gia_Man_t * pNew, int * pCtrl, int nCtrl, Vec_Int_t * vData, int Shift ) -{ - int iLit0, iLit1; - if ( nCtrl == 0 ) - return Vec_IntEntry( vData, Shift ); - iLit0 = Cba_NtkMuxTree_rec( pNew, pCtrl, nCtrl-1, vData, Shift ); - iLit1 = Cba_NtkMuxTree_rec( pNew, pCtrl, nCtrl-1, vData, Shift + (1<<(nCtrl-1)) ); - return Gia_ManHashMux( pNew, pCtrl[nCtrl-1], iLit1, iLit0 ); -} - -/**Function************************************************************* - - Synopsis [Bit blasting for specific operations.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_BlastShiftRight( Gia_Man_t * pNew, int * pNum, int nNum, int * pShift, int nShift, int fSticky, Vec_Int_t * vRes ) -{ - int * pRes = Cba_VecCopy( vRes, pNum, nNum ); - int Fill = fSticky ? pNum[nNum-1] : 0; - int i, j, fShort = 0; - if ( nShift > 32 ) - nShift = 32; - assert( nShift <= 32 ); - for( i = 0; i < nShift; i++ ) - for( j = 0; j < nNum - fSticky; j++ ) - { - if( fShort || j + (1<= nNum ) - { - pRes[j] = Gia_ManHashMux( pNew, pShift[i], Fill, pRes[j] ); - if ( (1< nNum ) - fShort = 1; - } - else - pRes[j] = Gia_ManHashMux( pNew, pShift[i], pRes[j+(1< 32 ) - nShift = 32; - assert( nShift <= 32 ); - for( i = 0; i < nShift; i++ ) - for( j = nNum-1; j >= fSticky; j-- ) - { - if( fShort || (1< j ) - { - pRes[j] = Gia_ManHashMux( pNew, pShift[i], Fill, pRes[j] ); - if ( (1< nNum ) - fShort = 1; - } - else - pRes[j] = Gia_ManHashMux( pNew, pShift[i], pRes[j-(1<= (1<= 0; k-- ) - { - iRes = Gia_ManHashMux( pNew, iKnown, iRes, Gia_ManHashAnd(pNew, Abc_LitNot(pArg0[k]), pArg1[k]) ); - iKnown = Gia_ManHashOr( pNew, iKnown, Gia_ManHashXor(pNew, pArg0[k], pArg1[k]) ); - if ( iKnown == 1 ) - break; - } - return iRes; -} -void Cba_BlastLess_rec( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits, int * pYes, int * pNo ) -{ - if ( nBits > 1 ) - { - int Yes = Gia_ManHashAnd( pNew, Abc_LitNot(pArg0[nBits-1]), pArg1[nBits-1] ), YesR; - int No = Gia_ManHashAnd( pNew, Abc_LitNot(pArg1[nBits-1]), pArg0[nBits-1] ), NoR; - if ( Yes == 1 || No == 1 ) - { - *pYes = Yes; - *pNo = No; - return; - } - Cba_BlastLess_rec( pNew, pArg0, pArg1, nBits-1, &YesR, &NoR ); - *pYes = Gia_ManHashOr( pNew, Yes, Gia_ManHashAnd(pNew, Abc_LitNot(No), YesR) ); - *pNo = Gia_ManHashOr( pNew, No, Gia_ManHashAnd(pNew, Abc_LitNot(Yes), NoR ) ); - return; - } - assert( nBits == 1 ); - *pYes = Gia_ManHashAnd( pNew, Abc_LitNot(pArg0[0]), pArg1[0] ); - *pNo = Gia_ManHashAnd( pNew, Abc_LitNot(pArg1[0]), pArg0[0] ); -} -int Cba_BlastLess( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits ) -{ - int Yes, No; - if ( nBits == 0 ) - return 0; - Cba_BlastLess_rec( pNew, pArg0, pArg1, nBits, &Yes, &No ); - return Yes; -} -int Cba_BlastLessSigned( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits ) -{ - int iDiffSign = Gia_ManHashXor( pNew, pArg0[nBits-1], pArg1[nBits-1] ); - return Gia_ManHashMux( pNew, iDiffSign, pArg0[nBits-1], Cba_BlastLess(pNew, pArg0, pArg1, nBits-1) ); -} -void Cba_BlastFullAdder( Gia_Man_t * pNew, int a, int b, int c, int * pc, int * ps ) -{ - int fUseXor = 0; - if ( fUseXor ) - { - int Xor = Gia_ManHashXor(pNew, a, b); - int And1 = Gia_ManHashAnd(pNew, a, b); - int And2 = Gia_ManHashAnd(pNew, c, Xor); - *ps = Gia_ManHashXor(pNew, c, Xor); - *pc = Gia_ManHashOr (pNew, And1, And2); - } - else - { - int And1 = Gia_ManHashAnd(pNew, a, b); - int And1_= Gia_ManHashAnd(pNew, Abc_LitNot(a), Abc_LitNot(b)); - int Xor = Abc_LitNot(Gia_ManHashOr(pNew, And1, And1_)); - int And2 = Gia_ManHashAnd(pNew, c, Xor); - int And2_= Gia_ManHashAnd(pNew, Abc_LitNot(c), Abc_LitNot(Xor)); - *ps = Abc_LitNot(Gia_ManHashOr(pNew, And2, And2_)); - *pc = Gia_ManHashOr (pNew, And1, And2); - } -} -int Cba_BlastAdder( Gia_Man_t * pNew, int Carry, int * pAdd0, int * pAdd1, int nBits ) // result is in pAdd0 -{ - int b; - for ( b = 0; b < nBits; b++ ) - Cba_BlastFullAdder( pNew, pAdd0[b], pAdd1[b], Carry, &Carry, &pAdd0[b] ); - return Carry; -} -void Cba_BlastSubtract( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits ) // result is in pAdd0 -{ - int b, Carry = 1; - for ( b = 0; b < nBits; b++ ) - Cba_BlastFullAdder( pNew, pAdd0[b], Abc_LitNot(pAdd1[b]), Carry, &Carry, &pAdd0[b] ); -} -void Cba_BlastMinus( Gia_Man_t * pNew, int * pNum, int nNum, Vec_Int_t * vRes ) -{ - int * pRes = Cba_VecCopy( vRes, pNum, nNum ); - int i, invert = 0; - for ( i = 0; i < nNum; i++ ) - { - pRes[i] = Gia_ManHashMux( pNew, invert, Abc_LitNot(pRes[i]), pRes[i] ); - invert = Gia_ManHashOr( pNew, invert, pNum[i] ); - } -} -void Cba_BlastMultiplier2( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits, Vec_Int_t * vTemp, Vec_Int_t * vRes ) -{ - int i, j; - Vec_IntFill( vRes, nBits, 0 ); - for ( i = 0; i < nBits; i++ ) - { - Vec_IntFill( vTemp, i, 0 ); - for ( j = 0; Vec_IntSize(vTemp) < nBits; j++ ) - Vec_IntPush( vTemp, Gia_ManHashAnd(pNew, pArg0[j], pArg1[i]) ); - assert( Vec_IntSize(vTemp) == nBits ); - Cba_BlastAdder( pNew, 0, Vec_IntArray(vRes), Vec_IntArray(vTemp), nBits ); - } -} -void Cba_BlastFullAdderCtrl( Gia_Man_t * pNew, int a, int ac, int b, int c, int * pc, int * ps, int fNeg ) -{ - int And = Abc_LitNotCond( Gia_ManHashAnd(pNew, a, ac), fNeg ); - Cba_BlastFullAdder( pNew, And, b, c, pc, ps ); -} -void Cba_BlastFullAdderSubtr( Gia_Man_t * pNew, int a, int b, int c, int * pc, int * ps, int fSub ) -{ - Cba_BlastFullAdder( pNew, Gia_ManHashXor(pNew, a, fSub), b, c, pc, ps ); -} -void Cba_BlastMultiplier( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vTemp, Vec_Int_t * vRes, int fSigned ) -{ - int * pRes, * pArgC, * pArgS, a, b, Carry = fSigned; - assert( nArgA > 0 && nArgB > 0 ); - assert( fSigned == 0 || fSigned == 1 ); - // prepare result - Vec_IntFill( vRes, nArgA + nArgB, 0 ); - pRes = Vec_IntArray( vRes ); - // prepare intermediate storage - Vec_IntFill( vTemp, 2 * nArgA, 0 ); - pArgC = Vec_IntArray( vTemp ); - pArgS = pArgC + nArgA; - // create matrix - for ( b = 0; b < nArgB; b++ ) - for ( a = 0; a < nArgA; a++ ) - Cba_BlastFullAdderCtrl( pNew, pArgA[a], pArgB[b], pArgS[a], pArgC[a], - &pArgC[a], a ? &pArgS[a-1] : &pRes[b], fSigned && ((a+1 == nArgA) ^ (b+1 == nArgB)) ); - // final addition - pArgS[nArgA-1] = fSigned; - for ( a = 0; a < nArgA; a++ ) - Cba_BlastFullAdderCtrl( pNew, 1, pArgC[a], pArgS[a], Carry, &Carry, &pRes[nArgB+a], 0 ); -} -void Cba_BlastDivider( Gia_Man_t * pNew, int * pNum, int nNum, int * pDiv, int nDiv, int fQuo, Vec_Int_t * vRes ) -{ - int * pRes = Cba_VecCopy( vRes, pNum, nNum ); - int * pQuo = ABC_ALLOC( int, nNum ); - int * pTemp = ABC_ALLOC( int, nNum ); - int i, j, known, borrow, y_bit, top_bit; - assert( nNum == nDiv ); - for ( j = nNum - 1; j >= 0; j-- ) - { - known = 0; - for ( i = nNum - 1; i > nNum - 1 - j; i-- ) - { - known = Gia_ManHashOr( pNew, known, pDiv[i] ); - if( known == 1 ) - break; - } - pQuo[j] = known; - for ( i = nNum - 1; i >= 0; i-- ) - { - if ( known == 1 ) - break; - y_bit = (i >= j) ? pDiv[i-j] : 0; - pQuo[j] = Gia_ManHashMux( pNew, known, pQuo[j], Gia_ManHashAnd( pNew, y_bit, Abc_LitNot(pRes[i]) ) ); - known = Gia_ManHashOr( pNew, known, Gia_ManHashXor(pNew, y_bit, pRes[i])); - } - pQuo[j] = Abc_LitNot(pQuo[j]); - if ( pQuo[j] == 0 ) - continue; - borrow = 0; - for ( i = 0; i < nNum; i++ ) - { - top_bit = Gia_ManHashMux( pNew, borrow, Abc_LitNot(pRes[i]), pRes[i] ); - y_bit = (i >= j) ? pDiv[i-j] : 0; - borrow = Gia_ManHashMux( pNew, pRes[i], Gia_ManHashAnd(pNew, borrow, y_bit), Gia_ManHashOr(pNew, borrow, y_bit) ); - pTemp[i] = Gia_ManHashXor( pNew, top_bit, y_bit ); - } - if ( pQuo[j] == 1 ) - Cba_VecCopy( vRes, pTemp, nNum ); - else - for( i = 0; i < nNum; i++ ) - pRes[i] = Gia_ManHashMux( pNew, pQuo[j], pTemp[i], pRes[i] ); - } - ABC_FREE( pTemp ); - if ( fQuo ) - Cba_VecCopy( vRes, pQuo, nNum ); - ABC_FREE( pQuo ); -} -// non-restoring divider -void Cba_BlastDivider2( Gia_Man_t * pNew, int * pNum, int nNum, int * pDiv, int nDiv, int fQuo, Vec_Int_t * vRes ) -{ - int i, * pRes = Vec_IntArray(vRes); - int k, * pQuo = ABC_ALLOC( int, nNum ); - assert( nNum > 0 && nDiv > 0 ); - assert( Vec_IntSize(vRes) < nNum + nDiv ); - for ( i = 0; i < nNum + nDiv; i++ ) - pRes[i] = i < nNum ? pNum[i] : 0; - for ( i = nNum-1; i >= 0; i-- ) - { - int Cntrl = i == nNum-1 ? 1 : pQuo[i+1]; - int Carry = Cntrl; - for ( k = 0; k <= nDiv; k++ ) - Cba_BlastFullAdderSubtr( pNew, k < nDiv ? pDiv[k] : 0, pRes[i+k], Carry, &Carry, &pRes[i+k], Cntrl ); - pQuo[i] = Abc_LitNot(pRes[i+nDiv]); - } - if ( fQuo ) - Cba_VecCopy( vRes, pQuo, nNum ); - else - { - int Carry = 0, Temp; - for ( k = 0; k < nDiv; k++ ) - { - Cba_BlastFullAdder( pNew, pDiv[k], pRes[k], Carry, &Carry, &Temp ); - pRes[k] = Gia_ManHashMux( pNew, pQuo[0], pRes[k], Temp ); - } - Vec_IntShrink( vRes, nDiv ); - } - ABC_FREE( pQuo ); -} -void Cba_BlastDividerSigned( Gia_Man_t * pNew, int * pNum, int nNum, int * pDiv, int nDiv, int fQuo, Vec_Int_t * vRes ) -{ - Vec_Int_t * vNum = Vec_IntAlloc( nNum ); - Vec_Int_t * vDiv = Vec_IntAlloc( nDiv ); - Vec_Int_t * vRes00 = Vec_IntAlloc( nNum + nDiv ); - Vec_Int_t * vRes01 = Vec_IntAlloc( nNum + nDiv ); - Vec_Int_t * vRes10 = Vec_IntAlloc( nNum + nDiv ); - Vec_Int_t * vRes11 = Vec_IntAlloc( nNum + nDiv ); - Vec_Int_t * vRes2 = Vec_IntAlloc( nNum ); - int k, iDiffSign = Gia_ManHashXor( pNew, pNum[nNum-1], pDiv[nDiv-1] ); - Cba_BlastMinus( pNew, pNum, nNum, vNum ); - Cba_BlastMinus( pNew, pDiv, nDiv, vDiv ); - Cba_BlastDivider( pNew, pNum, nNum, pDiv, nDiv, fQuo, vRes00 ); - Cba_BlastDivider( pNew, pNum, nNum, Vec_IntArray(vDiv), nDiv, fQuo, vRes01 ); - Cba_BlastDivider( pNew, Vec_IntArray(vNum), nNum, pDiv, nDiv, fQuo, vRes10 ); - Cba_BlastDivider( pNew, Vec_IntArray(vNum), nNum, Vec_IntArray(vDiv), nDiv, fQuo, vRes11 ); - Vec_IntClear( vRes ); - for ( k = 0; k < nNum; k++ ) - { - int Data0 = Gia_ManHashMux( pNew, pDiv[nDiv-1], Vec_IntEntry(vRes01,k), Vec_IntEntry(vRes00,k) ); - int Data1 = Gia_ManHashMux( pNew, pDiv[nDiv-1], Vec_IntEntry(vRes11,k), Vec_IntEntry(vRes10,k) ); - Vec_IntPush( vRes, Gia_ManHashMux(pNew, pNum[nNum-1], Data1, Data0) ); - } - Cba_BlastMinus( pNew, Vec_IntArray(vRes), nNum, vRes2 ); - for ( k = 0; k < nNum; k++ ) - Vec_IntWriteEntry( vRes, k, Gia_ManHashMux(pNew, fQuo ? iDiffSign : pNum[nNum-1], Vec_IntEntry(vRes2,k), Vec_IntEntry(vRes,k)) ); - Vec_IntFree( vNum ); - Vec_IntFree( vDiv ); - Vec_IntFree( vRes00 ); - Vec_IntFree( vRes01 ); - Vec_IntFree( vRes10 ); - Vec_IntFree( vRes11 ); - Vec_IntFree( vRes2 ); - assert( Vec_IntSize(vRes) == nNum ); -} -void Cba_BlastZeroCondition( Gia_Man_t * pNew, int * pDiv, int nDiv, Vec_Int_t * vRes ) -{ - int i, Entry, iLit = Cba_BlastReduction( pNew, pDiv, nDiv, CBA_BOX_ROR ); - Vec_IntForEachEntry( vRes, Entry, i ) - Vec_IntWriteEntry( vRes, i, Gia_ManHashAnd(pNew, iLit, Entry) ); -} -void Cba_BlastTable( Gia_Man_t * pNew, word * pTable, int * pFans, int nFans, int nOuts, Vec_Int_t * vRes ) -{ - extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash ); - Vec_Int_t * vMemory = Vec_IntAlloc( 0 ); - Vec_Int_t vLeaves = { nFans, nFans, pFans }; - word * pTruth = ABC_ALLOC( word, Abc_TtWordNum(nFans) ); - int o, i, m, iLit, nMints = (1 << nFans); - Vec_IntClear( vRes ); - for ( o = 0; o < nOuts; o++ ) - { - // derive truth table - memset( pTruth, 0, sizeof(word) * Abc_TtWordNum(nFans) ); - for ( m = 0; m < nMints; m++ ) - for ( i = 0; i < nFans; i++ ) - if ( Abc_TtGetBit( pTable, m * nFans + i ) ) - Abc_TtSetBit( pTruth, m ); - // implement truth table - if ( nFans < 6 ) - pTruth[0] = Abc_Tt6Stretch( pTruth[0], nFans ); - iLit = Kit_TruthToGia( pNew, (unsigned *)pTruth, nFans, vMemory, &vLeaves, 1 ); - Vec_IntPush( vRes, iLit ); - } - Vec_IntFree( vMemory ); - ABC_FREE( pTruth ); -} -void Cba_BlastPower( Gia_Man_t * pNew, int * pNum, int nNum, int * pExp, int nExp, Vec_Int_t * vTemp, Vec_Int_t * vRes ) -{ - Vec_Int_t * vDegrees = Vec_IntAlloc( 2*nNum ); - Vec_Int_t * vResTemp = Vec_IntAlloc( 2*nNum ); - int i, * pDegrees = NULL, * pRes = Vec_IntArray(vRes); - int k, * pResTemp = Vec_IntArray(vResTemp); - Vec_IntFill( vRes, nNum, 0 ); - Vec_IntWriteEntry( vRes, 0, 1 ); - for ( i = 0; i < nExp; i++ ) - { - if ( i == 0 ) - pDegrees = Cba_VecCopy( vDegrees, pNum, nNum ); - else - { - Cba_BlastMultiplier2( pNew, pDegrees, pDegrees, nNum, vTemp, vResTemp ); - pDegrees = Cba_VecCopy( vDegrees, pResTemp, nNum ); - } - Cba_BlastMultiplier2( pNew, pRes, pDegrees, nNum, vTemp, vResTemp ); - for ( k = 0; k < nNum; k++ ) - pRes[k] = Gia_ManHashMux( pNew, pExp[i], pResTemp[k], pRes[k] ); - } - Vec_IntFree( vResTemp ); - Vec_IntFree( vDegrees ); -} -void Cba_BlastSqrt( Gia_Man_t * pNew, int * pNum, int nNum, Vec_Int_t * vTmp, Vec_Int_t * vRes ) -{ - int * pRes, * pSum, * pSumP; - int i, k, Carry = -1; - assert( nNum % 2 == 0 ); - Vec_IntFill( vRes, nNum/2, 0 ); - Vec_IntFill( vTmp, 2*nNum, 0 ); - pRes = Vec_IntArray( vRes ); - pSum = Vec_IntArray( vTmp ); - pSumP = pSum + nNum; - for ( i = 0; i < nNum/2; i++ ) - { - pSumP[0] = pNum[nNum-2*i-2]; - pSumP[1] = pNum[nNum-2*i-1]; - for ( k = 0; k < i+1; k++ ) - pSumP[k+2] = pSum[k]; - for ( k = 0; k < i + 3; k++ ) - { - if ( k >= 2 && k < i + 2 ) // middle ones - Cba_BlastFullAdder( pNew, pSumP[k], Abc_LitNot(pRes[i-k+1]), Carry, &Carry, &pSum[k] ); - else - Cba_BlastFullAdder( pNew, pSumP[k], Abc_LitNot(k ? Carry:1), 1, &Carry, &pSum[k] ); - if ( k == 0 || k > i ) - Carry = Abc_LitNot(Carry); - } - pRes[i] = Abc_LitNot(Carry); - for ( k = 0; k < i + 3; k++ ) - pSum[k] = Gia_ManHashMux( pNew, pRes[i], pSum[k], pSumP[k] ); - } - Vec_IntReverseOrder( vRes ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Gia_Man_t * Cba_NtkBlast( Cba_Ntk_t * p, int fSeq ) -{ - int fUseOldMultiplierBlasting = 0; - Gia_Man_t * pTemp, * pNew; - Vec_Int_t * vTemp0, * vTemp1, * vTemp2, * vRes; - Vec_Str_t * vInit = fSeq ? Vec_StrAlloc(100) : NULL; - Vec_Int_t * vBits = &p->vFonBits; - int nBits = Cba_NtkPrepareBits( p ); - int * pFans0, * pFans1, * pFans2; - int nRange, nRange0, nRange1, nRange2; - int Type, iFon, iFon0, iFon1, iFon2, fSigned01; - int i, k, b, iFin, iObj, iLit, nAndPrev; - Vec_IntClear( vBits ); - Vec_IntGrow( vBits, nBits ); - vTemp0 = Vec_IntAlloc( 1000 ); - vTemp1 = Vec_IntAlloc( 1000 ); - vTemp2 = Vec_IntAlloc( 1000 ); - vRes = Vec_IntAlloc( 1000 ); - // clean AND-gate counters - memset( p->pDesign->nAnds, 0, sizeof(int) * CBA_BOX_LAST ); - // create AIG manager - pNew = Gia_ManStart( 5 * Cba_NtkObjNum(p) + 1000 ); - pNew->pName = Abc_UtilStrsav( Cba_ManName(p->pDesign) ); - Gia_ManHashAlloc( pNew ); - // blast in the topological order - Cba_NtkForEachObj( p, i ) - { - Type = Cba_ObjType(p, i); - if ( Type == CBA_OBJ_PO ) - continue; - assert( Vec_IntSize(vBits) == Cba_FonCopy(p, Cba_ObjFon0(p, i)) ); - nRange = Cba_ObjRangeSize(p, i); assert( nRange > 0 ); - if ( Cba_ObjIsPi(p, i) || Cba_ObjIsSeq(p, i) ) - { - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vBits, Gia_ManAppendCi(pNew) ); - assert( Type == CBA_BOX_DFFCPL || Cba_ObjFonNum(p, i) == 1 ); - continue; - } - assert( Cba_ObjFinNum(p, i) > 0 ); - iFon0 = Cba_ObjFinNum(p, i) > 0 ? Cba_ObjFinFon(p, i, 0) : -1; - iFon1 = Cba_ObjFinNum(p, i) > 1 ? Cba_ObjFinFon(p, i, 1) : -1; - iFon2 = Cba_ObjFinNum(p, i) > 2 ? Cba_ObjFinFon(p, i, 2) : -1; - nRange0 = Cba_ObjFinNum(p, i) > 0 ? Cba_FonRangeSize(p, iFon0) : -1; - nRange1 = Cba_ObjFinNum(p, i) > 1 ? Cba_FonRangeSize(p, iFon1) : -1; - nRange2 = Cba_ObjFinNum(p, i) > 2 ? Cba_FonRangeSize(p, iFon2) : -1; - pFans0 = (Cba_ObjFinNum(p, i) > 0 && Cba_FonIsReal(iFon0)) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon0) ) : NULL; - pFans1 = (Cba_ObjFinNum(p, i) > 1 && Cba_FonIsReal(iFon1)) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon1) ) : NULL; - pFans2 = (Cba_ObjFinNum(p, i) > 2 && Cba_FonIsReal(iFon2)) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon2) ) : NULL; - fSigned01 = (Cba_ObjFinNum(p, i) > 1 && Cba_FonSigned(p, iFon0) && Cba_FonSigned(p, iFon1)); - nAndPrev = Gia_ManAndNum(pNew); - Vec_IntClear( vRes ); - if ( Type == CBA_BOX_SLICE ) - { - int Left = Cba_ObjLeft( p, i ); - int Right = Cba_ObjRight( p, i ); - int Left0 = Cba_FonLeft( p, iFon0 ); - int Right0 = Cba_FonRight( p, iFon0 ); - if ( Left > Right ) - { - assert( Left0 > Right0 ); - for ( k = Right; k <= Left; k++ ) - Vec_IntPush( vRes, pFans0[k - Right0] ); - } - else - { - assert( Left < Right && Left0 < Right0 ); - for ( k = Right; k >= Left; k-- ) - Vec_IntPush( vRes, pFans0[k - Right0] ); - } - } - else if ( Type == CBA_BOX_CONCAT ) - { - int iFinT, iFonT, nTotal = 0; - Cba_ObjForEachFinFon( p, i, iFinT, iFonT, k ) - nTotal += Cba_FonRangeSize( p, iFonT ); - assert( nRange == nTotal ); - Cba_ObjForEachFinFon( p, i, iFinT, iFonT, k ) - { - nRange0 = Cba_FonRangeSize( p, iFonT ); - pFans0 = Cba_FonIsReal(iFonT) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFonT) ) : NULL; - pFans0 = Cba_VecLoadFanins( p, vTemp0, iFonT, pFans0, nRange0, nRange0, Cba_FonSigned(p, iFonT) ); - for ( b = 0; b < nRange0; b++ ) - Vec_IntPush( vRes, pFans0[b] ); - } - } - else if ( Type == CBA_BOX_BUF ) - { - int nRangeMax = Abc_MaxInt( nRange0, nRange ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, Cba_FonSigned(p, iFon0) ); - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vRes, pArg0[k] ); - } - else if ( Type >= CBA_BOX_CF && Type <= CBA_BOX_CZ ) - { - assert( 0 ); - //word * pTruth = (word *)Cba_ObjFanins(p, i); - //for ( k = 0; k < nRange; k++ ) - // Vec_IntPush( vRes, Abc_TtGetBit(pTruth, k) ); - } - else if ( Type == CBA_BOX_MUX || Type == CBA_BOX_NMUX ) - { - // It is strange and disturbing that Verilog standard treats these statements differently: - // Statement 1: - // assign o = i ? b : a; - // Statement 2: - // always @( i or a or b ) - // begin - // case ( i ) - // 0 : o = a ; - // 1 : o = b ; - // endcase - // end - // If a is signed and b is unsigned, Statement 1 does not sign-extend a, while Statement 2 does. - // The signedness of o does not matter. - // - // Below we (somewhat arbitrarily) distinguish these two by assuming that - // Statement 1 has three fanins, while Statement 2 has more than three fanins. - // - int iFinT, iFonT, fSigned = 1; - assert( nRange0 >= 1 && Cba_ObjFinNum(p, i) >= 3 ); - assert( 1 + (1 << nRange0) == Cba_ObjFinNum(p, i) ); - Cba_ObjForEachFinFon( p, i, iFinT, iFonT, k ) - if ( k > 0 ) - fSigned &= Cba_FonSigned(p, iFonT); - for ( b = 0; b < nRange; b++ ) - { - Vec_IntClear( vTemp0 ); - Cba_ObjForEachFinFon( p, i, iFinT, iFonT, k ) - if ( k > 0 ) - { - nRange1 = Cba_FonRangeSize( p, iFonT ); - pFans1 = Cba_FonIsReal(iFonT) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFonT) ) : NULL; - if ( Cba_ObjFinNum(p, i) == 3 ) // Statement 1 - Vec_IntPush( vTemp0, k < nRange1 ? pFans1[k] : (fSigned? pFans1[nRange1-1] : 0) ); - else // Statement 2 - Vec_IntPush( vTemp0, k < nRange1 ? pFans1[k] : (Cba_FonSigned(p, iFonT)? pFans1[nRange1-1] : 0) ); - } - Vec_IntPush( vRes, Cba_NtkMuxTree_rec(pNew, pFans0, nRange0, vTemp0, 0) ); - } - } - else if ( Type == CBA_BOX_SHIR || Type == CBA_BOX_SHIRA || - Type == CBA_BOX_SHIL || Type == CBA_BOX_SHILA ) - { - int nRangeMax = Abc_MaxInt( nRange, nRange0 ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, Cba_FonSigned(p, iFon0) ); - if ( Type == CBA_BOX_SHIR || Type == CBA_BOX_SHIRA ) - Cba_BlastShiftRight( pNew, pArg0, nRangeMax, pFans1, nRange1, Cba_FonSigned(p, iFon0) && Type == CBA_BOX_SHIRA, vRes ); - else - Cba_BlastShiftLeft( pNew, pArg0, nRangeMax, pFans1, nRange1, 0, vRes ); - Vec_IntShrink( vRes, nRange ); - } - else if ( Type == CBA_BOX_ROTR ) - { - assert( nRange0 == nRange ); - Cba_BlastRotateRight( pNew, pFans0, nRange0, pFans1, nRange1, vRes ); - } - else if ( Type == CBA_BOX_ROTL ) - { - assert( nRange0 == nRange ); - Cba_BlastRotateLeft( pNew, pFans0, nRange0, pFans1, nRange1, vRes ); - } - else if ( Type == CBA_BOX_INV ) - { - int nRangeMax = Abc_MaxInt( nRange, nRange0 ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, Cba_FonSigned(p, iFon0) ); - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vRes, Abc_LitNot(pArg0[k]) ); - } - else if ( Type == CBA_BOX_AND ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vRes, Gia_ManHashAnd(pNew, pArg0[k], pArg1[k]) ); - } - else if ( Type == CBA_BOX_OR ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vRes, Gia_ManHashOr(pNew, pArg0[k], pArg1[k]) ); - } - else if ( Type == CBA_BOX_XOR ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - for ( k = 0; k < nRange; k++ ) - Vec_IntPush( vRes, Gia_ManHashXor(pNew, pArg0[k], pArg1[k]) ); - } - else if ( Type == CBA_BOX_LNOT ) - { - iLit = Cba_BlastReduction( pNew, pFans0, nRange0, CBA_BOX_ROR ); - Vec_IntFill( vRes, 1, Abc_LitNot(iLit) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_LAND ) - { - int iLit0 = Cba_BlastReduction( pNew, pFans0, nRange0, CBA_BOX_ROR ); - int iLit1 = Cba_BlastReduction( pNew, pFans1, nRange1, CBA_BOX_ROR ); - Vec_IntFill( vRes, 1, Gia_ManHashAnd(pNew, iLit0, iLit1) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_LOR ) - { - int iLit0 = Cba_BlastReduction( pNew, pFans0, nRange0, CBA_BOX_ROR ); - int iLit1 = Cba_BlastReduction( pNew, pFans1, nRange1, CBA_BOX_ROR ); - Vec_IntFill( vRes, 1, Gia_ManHashOr(pNew, iLit0, iLit1) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_LXOR ) - { - int iLit0 = Cba_BlastReduction( pNew, pFans0, nRange0, CBA_BOX_ROR ); - int iLit1 = Cba_BlastReduction( pNew, pFans1, nRange1, CBA_BOX_ROR ); - Vec_IntFill( vRes, 1, Gia_ManHashXor(pNew, iLit0, iLit1) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_EQU || Type == CBA_BOX_NEQU ) - { - int iLit = 0, nRangeMax = Abc_MaxInt( nRange0, nRange1 ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - for ( k = 0; k < nRangeMax; k++ ) - iLit = Gia_ManHashOr( pNew, iLit, Gia_ManHashXor(pNew, pArg0[k], pArg1[k]) ); - Vec_IntFill( vRes, 1, Abc_LitNotCond(iLit, Type == CBA_BOX_EQU) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_LTHAN || Type == CBA_BOX_METHAN || - Type == CBA_BOX_MTHAN || Type == CBA_BOX_LETHAN ) - { - int nRangeMax = Abc_MaxInt( nRange0, nRange1 ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - int fSwap = (Type == CBA_BOX_MTHAN || Type == CBA_BOX_LETHAN); - int fCompl = (Type == CBA_BOX_METHAN || Type == CBA_BOX_LETHAN); - if ( fSwap ) ABC_SWAP( int *, pArg0, pArg1 ); - if ( fSigned01 ) - iLit = Cba_BlastLessSigned( pNew, pArg0, pArg1, nRangeMax ); - else - iLit = Cba_BlastLess( pNew, pArg0, pArg1, nRangeMax ); - iLit = Abc_LitNotCond( iLit, fCompl ); - Vec_IntFill( vRes, 1, iLit ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_RAND || Type == CBA_BOX_ROR || Type == CBA_BOX_RXOR ) - { - Vec_IntPush( vRes, Cba_BlastReduction( pNew, pFans0, nRange0, Type ) ); - for ( k = 1; k < nRange; k++ ) - Vec_IntPush( vRes, 0 ); - } - else if ( Type == CBA_BOX_ADD ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange1, nRange2) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, 1, 1, 0 ); - int * pArg1 = Cba_VecLoadFanins( p, vRes, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - int * pArg2 = Cba_VecLoadFanins( p, vTemp1, iFon2, pFans2, nRange2, nRangeMax, fSigned01 ); - int Carry = Cba_BlastAdder( pNew, pArg0[0], pArg1, pArg2, nRange ); // result is in pArg1 (vRes) - assert( nRange0 == 1 ); - Vec_IntShrink( vRes, nRange ); - Vec_IntPush( vRes, Carry ); - } - else if ( Type == CBA_BOX_SUB ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vRes, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - Cba_BlastSubtract( pNew, pArg0, pArg1, nRange ); // result is in pFan0 (vRes) - Vec_IntShrink( vRes, nRange ); - } - else if ( Type == CBA_BOX_MUL ) - { - if ( fUseOldMultiplierBlasting ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - Cba_BlastMultiplier2( pNew, pArg0, pArg1, nRange, vTemp2, vRes ); - Vec_IntShrink( vRes, nRange ); - } - else - { - int nRangeMax = Abc_MaxInt(nRange0, nRange1); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - Cba_BlastMultiplier( pNew, pArg0, pArg1, nRangeMax, nRangeMax, vTemp2, vRes, fSigned01 ); - if ( nRange > nRangeMax + nRangeMax ) - Vec_IntFillExtra( vRes, nRange, fSigned01 ? Vec_IntEntryLast(vRes) : 0 ); - else - Vec_IntShrink( vRes, nRange ); - assert( Vec_IntSize(vRes) == nRange ); - } - } - else if ( Type == CBA_BOX_DIV || Type == CBA_BOX_MOD ) - { - int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(nRange0, nRange1) ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, fSigned01 ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRangeMax, fSigned01 ); - if ( fSigned01 ) - Cba_BlastDividerSigned( pNew, pArg0, nRangeMax, pArg1, nRangeMax, Type == CBA_BOX_DIV, vRes ); - else - Cba_BlastDivider( pNew, pArg0, nRangeMax, pArg1, nRangeMax, Type == CBA_BOX_DIV, vRes ); - Vec_IntShrink( vRes, nRange ); - if ( Type == CBA_BOX_DIV ) - Cba_BlastZeroCondition( pNew, pFans1, nRange1, vRes ); - } - else if ( Type == CBA_BOX_MIN ) - { - int nRangeMax = Abc_MaxInt( nRange0, nRange ); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, Cba_FonSigned(p, iFon0) ); - Cba_BlastMinus( pNew, pArg0, nRangeMax, vRes ); - Vec_IntShrink( vRes, nRange ); - } - else if ( Type == CBA_BOX_POW ) - { - int nRangeMax = Abc_MaxInt(nRange0, nRange); - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRangeMax, Cba_FonSigned(p, iFon0) ); - int * pArg1 = Cba_VecLoadFanins( p, vTemp1, iFon1, pFans1, nRange1, nRange1, Cba_FonSigned(p, iFon1) ); - Cba_BlastPower( pNew, pArg0, nRangeMax, pArg1, nRange1, vTemp2, vRes ); - Vec_IntShrink( vRes, nRange ); - } - else if ( Type == CBA_BOX_SQRT ) - { - int * pArg0 = Cba_VecLoadFanins( p, vTemp0, iFon0, pFans0, nRange0, nRange0 + (nRange0 & 1), 0 ); - nRange0 += (nRange0 & 1); - Cba_BlastSqrt( pNew, pArg0, nRange0, vTemp2, vRes ); - if ( nRange > Vec_IntSize(vRes) ) - Vec_IntFillExtra( vRes, nRange, 0 ); - else - Vec_IntShrink( vRes, nRange ); - } - else if ( Type == CBA_BOX_TABLE ) - { - assert( 0 ); - //Cba_BlastTable( pNew, Cba_ObjTable(p, p, i), pFans0, nRange0, nRange, vRes ); - } - else assert( 0 ); - Vec_IntAppend( vBits, vRes ); - p->pDesign->nAnds[Type] += Gia_ManAndNum(pNew) - nAndPrev; - } - assert( nBits == Vec_IntSize(vBits) ); - p->pDesign->nAnds[0] = Gia_ManAndNum(pNew); - // create COs - Cba_NtkForEachPo( p, iObj, i ) - { - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - { - nRange = Cba_FonRangeSize( p, iFon ); - pFans0 = Cba_FonIsReal(iFon) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon) ) : NULL; - pFans0 = Cba_VecLoadFanins( p, vTemp0, iFon, pFans0, nRange, nRange, Cba_FonSigned(p, iFon) ); - for ( b = 0; b < nRange; b++ ) - Gia_ManAppendCo( pNew, pFans0[b] ); - } - } - Cba_NtkForEachBoxSeq( p, iObj, i ) - { - if ( fSeq ) - { - assert( Cba_ObjType(p, iObj) == CBA_BOX_DFFCPL ); - iFon0 = Cba_ObjFinFon( p, iObj, 0 ); - iFon1 = Cba_ObjFinFon( p, iObj, 1 ); - nRange0 = Cba_FonRangeSize( p, iFon0 ); - nRange1 = Cba_FonRangeSize( p, iFon1 ); - assert( nRange0 == nRange1 ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - { - nRange = Cba_FonRangeSize( p, iFon ); - pFans0 = Cba_FonIsReal(iFon) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon) ) : NULL; - pFans0 = Cba_VecLoadFanins( p, vTemp0, iFon, pFans0, nRange0, nRange0, Cba_FonSigned(p, iFon) ); - if ( k == 0 ) - { - for ( b = 0; b < nRange; b++ ) - Gia_ManAppendCo( pNew, pFans0[b] ); - } - else if ( k == 1 ) - { - for ( b = 0; b < nRange; b++ ) - if ( pFans0[b] == 0 ) - Vec_StrPush( vInit, '0' ); - else if ( pFans0[b] == 1 ) - Vec_StrPush( vInit, '1' ); - else - Vec_StrPush( vInit, 'x' ); - } - else break; - } - } - else // combinational - { - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - { - nRange = Cba_FonRangeSize( p, iFon ); - pFans0 = Cba_FonIsReal(iFon) ? Vec_IntEntryP( vBits, Cba_FonCopy(p, iFon) ) : NULL; - pFans0 = Cba_VecLoadFanins( p, vTemp0, iFon, pFans0, nRange, nRange, Cba_FonSigned(p, iFon) ); - for ( b = 0; b < nRange; b++ ) - Gia_ManAppendCo( pNew, pFans0[b] ); - } - } - } - Vec_IntFree( vTemp0 ); - Vec_IntFree( vTemp1 ); - Vec_IntFree( vTemp2 ); - Vec_IntFree( vRes ); - // finalize AIG - pNew = Gia_ManCleanup( pTemp = pNew ); - Gia_ManDupRemapLiterals( vBits, pTemp ); - Gia_ManStop( pTemp ); - // transform AIG with init state - if ( fSeq ) - { - Gia_ManSetRegNum( pNew, Vec_StrSize(vInit) ); - Vec_StrPush( vInit, '\0' ); - pNew = Gia_ManDupZeroUndc( pTemp = pNew, Vec_StrArray(vInit), 0, 0, 1 ); - Gia_ManDupRemapLiterals( vBits, pTemp ); - Gia_ManStop( pTemp ); - Vec_StrFreeP( &vInit ); - } - //Vec_IntErase( vBits ); - //Vec_IntErase( &p->vCopies ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Gia_Man_t * Cba_ManBlast( Cba_Man_t * p, int fBarBufs, int fSeq, int fVerbose ) -{ - return Cba_NtkBlast( Cba_ManRoot(p), fSeq ); -} - -/**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 /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaCba.c b/src/base/cba/cbaCba.c deleted file mode 100644 index 2275c948c..000000000 --- a/src/base/cba/cbaCba.c +++ /dev/null @@ -1,58 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaCba.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Reading binary representation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - Revision [$Id: cbaCba.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Cba_Man_t * Cba_ManReadCba( char * pFileName ) -{ - return NULL; -} -void Cba_ManWriteCba( char * pFileName, Cba_Man_t * p ) -{ -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaCom.c b/src/base/cba/cbaCom.c deleted file mode 100644 index fa13030ab..000000000 --- a/src/base/cba/cbaCom.c +++ /dev/null @@ -1,731 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaCom.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Command handlers.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaCom.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" -#include "proof/cec/cec.h" -#include "base/main/mainInt.h" - -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 ); -static int Cba_CommandPut ( Abc_Frame_t * pAbc, int argc, char ** argv ); -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_CommandBlast ( 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; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -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 ); - Cmd_CommandAdd( pAbc, "New word level", ":put", Cba_CommandPut, 0 ); - Cmd_CommandAdd( pAbc, "New word level", ":get", Cba_CommandGet, 0 ); - Cmd_CommandAdd( pAbc, "New word level", ":clp", Cba_CommandClp, 0 ); - Cmd_CommandAdd( pAbc, "New word level", ":blast", Cba_CommandBlast, 0 ); - Cmd_CommandAdd( pAbc, "New word level", ":cec", Cba_CommandCec, 0 ); - Cmd_CommandAdd( pAbc, "New word level", ":test", Cba_CommandTest, 0 ); -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Cba_End( Abc_Frame_t * pAbc ) -{ - Cba_AbcFreeMan( pAbc ); -} - - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - FILE * pFile; - Cba_Man_t * p = NULL; - char * pFileName = NULL; - int c, fTest = 0, fDfs = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "tdvh" ) ) != EOF ) - { - switch ( c ) - { - case 't': - fTest ^= 1; - break; - case 'd': - fDfs ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( argc != globalUtilOptind + 1 ) - { - printf( "Cba_CommandRead(): Input file name should be given on the command line.\n" ); - return 0; - } - // get the file name - pFileName = argv[globalUtilOptind]; - if ( (pFile = fopen( pFileName, "r" )) == NULL ) - { - Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName ); - if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".blif", ".smt", ".cba", NULL )) ) - Abc_Print( 1, "Did you mean \"%s\"?", pFileName ); - Abc_Print( 1, "\n" ); - return 0; - } - fclose( pFile ); - if ( fTest ) - { - if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - Prs_ManReadBlifTest( pFileName ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - Prs_ManReadVerilogTest( pFileName ); - else - { - printf( "Unrecognized input file extension.\n" ); - return 0; - } - return 0; - } - if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - p = Cba_ManReadBlif( pFileName ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - p = Cba_ManReadVerilog( pFileName ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) - p = Cba_ManReadCba( pFileName ); - else - { - printf( "Unrecognized input file extension.\n" ); - return 0; - } - if ( fDfs ) - { - Cba_Man_t * pTemp; - p = Cba_ManDup( pTemp = p, Cba_NtkCollectDfs ); - Cba_ManFree( pTemp ); - } - Cba_AbcUpdateMan( pAbc, p ); - return 0; -usage: - Abc_Print( -2, "usage: :read [-tdvh] \n" ); - Abc_Print( -2, "\t reads hierarchical design\n" ); - Abc_Print( -2, "\t-t : toggle testing the parser [default = %s]\n", fTest? "yes": "no" ); - Abc_Print( -2, "\t-d : toggle computing DFS ordering [default = %s]\n", fDfs? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandWrite( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * p = Cba_AbcGetMan(pAbc); - char * pFileName = NULL; - int fInclineCats = 0; - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "cvh" ) ) != EOF ) - { - switch ( c ) - { - case 'c': - fInclineCats ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandWrite(): There is no current design.\n" ); - return 0; - } - - if ( argc == globalUtilOptind + 1 ) - pFileName = argv[globalUtilOptind]; - else if ( argc == globalUtilOptind && p ) - { - pFileName = Extra_FileNameGenericAppend( Cba_ManSpec(p) ? Cba_ManSpec(p) : Cba_ManName(p), "_out.v" ); - printf( "Generated output file name \"%s\".\n", pFileName ); - } - else - { - printf( "Output file name should be given on the command line.\n" ); - return 0; - } - // perform writing - if ( !strcmp( Extra_FileNameExtension(pFileName), "blif" ) ) - Cba_ManWriteBlif( pFileName, p ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - Cba_ManWriteVerilog( pFileName, p, fInclineCats ); - else if ( !strcmp( Extra_FileNameExtension(pFileName), "cba" ) ) - Cba_ManWriteCba( pFileName, p ); - else - { - printf( "Unrecognized output file extension.\n" ); - return 0; - } - return 0; -usage: - 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-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; -} - - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * p = Cba_AbcGetMan(pAbc); - int nModules = 0; - int fShowMulti = 0; - int fShowAdder = 0; - int fDistrib = 0; - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "Mmadvh" ) ) != EOF ) - { - switch ( c ) - { - case 'M': - if ( globalUtilOptind >= argc ) - { - Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" ); - goto usage; - } - nModules = atoi(argv[globalUtilOptind]); - globalUtilOptind++; - if ( nModules < 0 ) - goto usage; - break; - case 'm': - fShowMulti ^= 1; - break; - case 'a': - fShowAdder ^= 1; - break; - case 'd': - fDistrib ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandPs(): There is no current design.\n" ); - return 0; - } - if ( nModules ) - { - Cba_ManPrintStats( p, nModules, fVerbose ); - return 0; - } - Cba_NtkPrintStatsFull( Cba_ManRoot(p), fDistrib, fVerbose ); - if ( fShowMulti ) - Cba_NtkPrintNodes( Cba_ManRoot(p), CBA_BOX_MUL ); - if ( fShowAdder ) - Cba_NtkPrintNodes( Cba_ManRoot(p), CBA_BOX_ADD ); - return 0; -usage: - Abc_Print( -2, "usage: :ps [-M num] [-madvh]\n" ); - Abc_Print( -2, "\t prints statistics\n" ); - Abc_Print( -2, "\t-M num : the number of first modules to report [default = %d]\n", nModules ); - Abc_Print( -2, "\t-m : toggle printing multipliers [default = %s]\n", fShowMulti? "yes": "no" ); - Abc_Print( -2, "\t-a : toggle printing adders [default = %s]\n", fShowAdder? "yes": "no" ); - Abc_Print( -2, "\t-d : toggle printing distrubition [default = %s]\n", fDistrib? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandPut( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * p = Cba_AbcGetMan(pAbc); - Gia_Man_t * pGia = NULL; - int c, fBarBufs = 1, fSeq = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "bsvh" ) ) != EOF ) - { - switch ( c ) - { - case 'b': - fBarBufs ^= 1; - break; - case 's': - fSeq ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandPut(): There is no current design.\n" ); - return 0; - } - pGia = Cba_ManBlast( p, fBarBufs, fSeq, fVerbose ); - if ( pGia == NULL ) - { - Abc_Print( 1, "Cba_CommandPut(): Conversion to AIG has failed.\n" ); - return 0; - } - Abc_FrameUpdateGia( pAbc, pGia ); - return 0; -usage: - Abc_Print( -2, "usage: :put [-bsvh]\n" ); - Abc_Print( -2, "\t extracts AIG from the hierarchical design\n" ); - Abc_Print( -2, "\t-b : toggle using barrier buffers [default = %s]\n", fBarBufs? "yes": "no" ); - Abc_Print( -2, "\t-s : toggle blasting sequential elements [default = %s]\n", fSeq? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandGet( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * pNew = NULL, * p = Cba_AbcGetMan(pAbc); - int c, fMapped = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF ) - { - switch ( c ) - { - case 'm': - fMapped ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandGet(): There is no current design.\n" ); - return 0; - } - - if ( fMapped ) - { - if ( pAbc->pNtkCur == NULL ) - { - Abc_Print( 1, "Cba_CommandGet(): There is no current mapped design.\n" ); - return 0; - } - pNew = Cba_ManInsertAbc( p, pAbc->pNtkCur ); - } - else - { - if ( pAbc->pGia == NULL ) - { - Abc_Print( 1, "Cba_CommandGet(): There is no current AIG.\n" ); - return 0; - } - pNew = Cba_ManInsertGia( p, pAbc->pGia ); - } - Cba_AbcUpdateMan( pAbc, pNew ); - return 0; -usage: - Abc_Print( -2, "usage: :get [-mvh]\n" ); - Abc_Print( -2, "\t extracts AIG or mapped network into the hierarchical design\n" ); - Abc_Print( -2, "\t-m : toggle using mapped network from main-space [default = %s]\n", fMapped? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandClp( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * pNew = NULL, * p = Cba_AbcGetMan(pAbc); - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandGet(): There is no current design.\n" ); - return 0; - } - pNew = Cba_ManCollapse( p ); - Cba_AbcUpdateMan( pAbc, pNew ); - return 0; -usage: - Abc_Print( -2, "usage: :clp [-vh]\n" ); - Abc_Print( -2, "\t collapses the current hierarchical design\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Gia_Man_t * pNew = NULL; - Cba_Man_t * p = Cba_AbcGetMan(pAbc); - int c, fSeq = 0, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "svh" ) ) != EOF ) - { - switch ( c ) - { - case 's': - fSeq ^= 1; - break; - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandBlast(): There is no current design.\n" ); - return 0; - } - pNew = Cba_ManBlast( p, 0, fSeq, fVerbose ); - if ( pNew == NULL ) - { - Abc_Print( 1, "Cba_CommandBlast(): Bit-blasting has failed.\n" ); - return 0; - } - Abc_FrameUpdateGia( pAbc, pNew ); - return 0; -usage: - Abc_Print( -2, "usage: :blast [-svh]\n" ); - Abc_Print( -2, "\t performs bit-blasting of the word-level design\n" ); - Abc_Print( -2, "\t-s : toggle blasting sequential elements [default = %s]\n", fSeq? "yes": "no" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * p = Cba_AbcGetMan(pAbc), * pTemp; - Gia_Man_t * pFirst, * pSecond, * pMiter; - Cec_ParCec_t ParsCec, * pPars = &ParsCec; - char * pFileName, * pStr, ** pArgvNew; - int c, nArgcNew, fDumpMiter = 0; - FILE * pFile; - Cec_ManCecSetDefaultParams( pPars ); - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - pPars->fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandCec(): There is no current design.\n" ); - return 0; - } - - pArgvNew = argv + globalUtilOptind; - nArgcNew = argc - globalUtilOptind; - if ( nArgcNew != 1 ) - { - if ( p->pSpec == NULL ) - { - Abc_Print( -1, "File name is not given on the command line.\n" ); - return 1; - } - pFileName = p->pSpec; - } - else - pFileName = pArgvNew[0]; - // fix the wrong symbol - for ( pStr = pFileName; *pStr; pStr++ ) - if ( *pStr == '>' ) - *pStr = '\\'; - if ( (pFile = fopen( pFileName, "r" )) == NULL ) - { - 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_ManBlast( p, 0, 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(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 ); - pSecond = Cba_ManBlast( pTemp, 0, 0, 0 ); - Cba_ManFree( pTemp ); - if ( pSecond == NULL ) - { - Gia_ManStop( pFirst ); - Abc_Print( -1, "Extracting AIG from the original design has failed.\n" ); - return 0; - } - // compute the miter - pMiter = Gia_ManMiter( pFirst, pSecond, 0, 1, 0, 0, pPars->fVerbose ); - if ( pMiter ) - { - if ( fDumpMiter ) - { - Abc_Print( 0, "The verification miter is written into file \"%s\".\n", "cec_miter.aig" ); - Gia_AigerWrite( pMiter, "cec_miter.aig", 0, 0, 0 ); - } - pAbc->Status = Cec_ManVerify( pMiter, pPars ); - //Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb ); - Gia_ManStop( pMiter ); - } - Gia_ManStop( pFirst ); - Gia_ManStop( pSecond ); - return 0; -usage: - Abc_Print( -2, "usage: :cec [-vh]\n" ); - Abc_Print( -2, "\t combinational equivalence checking\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -/**Function******************************************************************** - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -int Cba_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - Cba_Man_t * p = Cba_AbcGetMan(pAbc); - int c, fVerbose = 0; - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) - { - switch ( c ) - { - case 'v': - fVerbose ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( p == NULL ) - { - Abc_Print( 1, "Cba_CommandTest(): There is no current design.\n" ); - return 0; - } - return 0; -usage: - Abc_Print( -2, "usage: :test [-vh]\n" ); - Abc_Print( -2, "\t experiments with word-level networks\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaNtk.c b/src/base/cba/cbaNtk.c deleted file mode 100644 index c3f8fae94..000000000 --- a/src/base/cba/cbaNtk.c +++ /dev/null @@ -1,1183 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaNtk.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Network manipulation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - Revision [$Id: cbaNtk.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include -#include "cba.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Prints distribution of operator types.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Vec_WrdSelectSortCost2( word * pArray, int nSize, word * pCosts ) -{ - int i, j, best_i; - for ( i = 0; i < nSize-1; i++ ) - { - best_i = i; - for ( j = i+1; j < nSize; j++ ) - if ( pCosts[j] < pCosts[best_i] ) - best_i = j; - ABC_SWAP( word, pArray[i], pArray[best_i] ); - ABC_SWAP( word, pCosts[i], pCosts[best_i] ); - } -} -static inline word Cba_NtkPrintDistribMakeSign( int s, int s0, int s1 ) -{ - return ((word)s1 << 42) | ((word)s0 << 21) | (word)s; -} -static inline void Cba_NtkPrintDistribFromSign( word sss, int * s, int * s0, int * s1 ) -{ - *s1 = (int)(sss >> 42); *s0 = (int)(sss >> 21) & 0x1FFFFF; *s = (int)sss & 0x1FFFFF; -} -static inline void Cba_NtkPrintDistribAddOne( Vec_Ptr_t * vTypes, Vec_Ptr_t * vOccurs, int Type, word Sign ) -{ - Vec_Wrd_t * vType = (Vec_Wrd_t *)Vec_PtrEntry( vTypes, Type ); - Vec_Wrd_t * vOccur = (Vec_Wrd_t *)Vec_PtrEntry( vOccurs, Type ); - word Entry; int i; - Vec_WrdForEachEntry( vType, Entry, i ) - if ( Entry == Sign ) - { - Vec_WrdAddToEntry( vOccur, i, 1 ); - return; - } - Vec_WrdPush( vType, Sign ); - Vec_WrdPush( vOccur, 1 ); -} -void Cba_NtkPrintDistribSortOne( Vec_Ptr_t * vTypes, Vec_Ptr_t * vOccurs, int Type ) -{ - Vec_Wrd_t * vType = (Vec_Wrd_t *)Vec_PtrEntry( vTypes, Type ); - Vec_Wrd_t * vOccur = (Vec_Wrd_t *)Vec_PtrEntry( vOccurs, Type ); - Vec_WrdSelectSortCost2( Vec_WrdArray(vType), Vec_WrdSize(vType), Vec_WrdArray(vOccur) ); - Vec_WrdReverseOrder( vType ); - Vec_WrdReverseOrder( vOccur ); -} -void Cba_NtkPrintDistrib( Cba_Ntk_t * p, int fVerbose ) -{ - Vec_Ptr_t * vTypes, * vOccurs; - Vec_Int_t * vAnds = Vec_IntStart( CBA_BOX_LAST ); - int iRnObj = -1, nCountRange = 0; - int i, k, s, s0, s1; word Sign; - Cba_ObjType_t Type; - char * pTypeNames[CBA_BOX_LAST]; - Cba_ManCreatePrimMap( pTypeNames ); - // allocate statistics arrays - vTypes = Vec_PtrStart( CBA_BOX_LAST ); - vOccurs = Vec_PtrStart( CBA_BOX_LAST ); - for ( i = 0; i < CBA_BOX_LAST; i++ ) - Vec_PtrWriteEntry( vTypes, i, Vec_WrdAlloc(16) ); - for ( i = 0; i < CBA_BOX_LAST; i++ ) - Vec_PtrWriteEntry( vOccurs, i, Vec_WrdAlloc(16) ); - // add nodes - Cba_NtkForEachObj( p, i ) - { -// char * pName = Cba_ObjName(p, i); - Type = Cba_ObjType( p, i ); - if ( Cba_ObjSign(p, i) > 0x1FFFFF ) - printf( "Object %6d has range %d, which is reduced to %d in the statistics.\n", - i, Cba_ObjRangeSize(p, i), Cba_ObjRangeSize(p, i) & 0xFFFFF ); - if ( Cba_ObjLeft(p, i) && Cba_ObjRight(p, i) ) - { - if ( iRnObj == -1 ) - iRnObj = 1; - nCountRange++; - } - // 0-input types - if ( Cba_ObjIsPi(p, i) || (Type == CBA_BOX_BUF && Cba_FonIsConst(Cba_ObjFinFon(p, i, 0))) || Type == CBA_BOX_CONCAT ) - Sign = Cba_NtkPrintDistribMakeSign( Cba_ObjSign(p, i), 0, 0 ); - // 1-input types - else if ( Cba_TypeIsUnary(Type) ) - Sign = Cba_NtkPrintDistribMakeSign( Cba_ObjSign(p, i), Cba_ObjSign(p, Cba_ObjFinFon(p, i, 0)), 0 ); - // 2-input types (including MUX) - else if ( Cba_ObjFinNum(p, i) == 1 ) - Sign = Cba_NtkPrintDistribMakeSign( Cba_ObjSign(p, i), Cba_ObjSign(p, Cba_ObjFinFon(p, i, 0)), 0 ); - else - { - assert( Cba_ObjFinNum(p, i) >= 2 ); - Sign = Cba_NtkPrintDistribMakeSign( Cba_ObjSign(p, i), Cba_ObjSign(p, Cba_ObjFinFon(p, i, 0)), Cba_ObjSign(p, Cba_ObjFinFon(p, i, 1)) ); - } - // add to storage - Cba_NtkPrintDistribAddOne( vTypes, vOccurs, Type, Sign ); - // count the number of AIG nodes - if ( Type == CBA_BOX_MUX ) - Vec_IntAddToEntry( vAnds, CBA_BOX_MUX, 3 * Cba_ObjRangeSize(p, i) * (Cba_ObjFinNum(p, i) - 2) ); - else if ( Type == CBA_BOX_SHIR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SHIR, Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_SHIRA ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SHIRA, Cba_ObjRangeSize(p, i) * Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_SHIL ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SHIL, Cba_ObjRangeSize(p, i) * Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_SHILA ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SHILA, Cba_ObjRangeSize(p, i) * Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_ROTR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_ROTR, Cba_ObjRangeSize(p, i) * Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_ROTL ) - Vec_IntAddToEntry( vAnds, CBA_BOX_ROTL, Cba_ObjRangeSize(p, i) * Abc_MinInt(Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Abc_Base2Log(Cba_ObjRangeSize(p, i))) * 3 ); - else if ( Type == CBA_BOX_INV ) - Vec_IntAddToEntry( vAnds, CBA_BOX_INV, 0 ); - else if ( Type == CBA_BOX_AND ) - Vec_IntAddToEntry( vAnds, CBA_BOX_AND, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_OR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_OR, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_XOR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_XOR, 3 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_SLICE ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SLICE, 0 ); - else if ( Type == CBA_BOX_CONCAT ) - Vec_IntAddToEntry( vAnds, CBA_BOX_CONCAT, 0 ); - else if ( Type == CBA_BOX_LNOT ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LNOT, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 1 ); - else if ( Type == CBA_BOX_LAND ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LAND, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) + Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 1)) - 1 ); - else if ( Type == CBA_BOX_LOR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LOR, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) + Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 1)) - 1 ); - else if ( Type == CBA_BOX_LXOR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LXOR, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) + Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 1)) + 1 ); - else if ( Type == CBA_BOX_EQU ) - Vec_IntAddToEntry( vAnds, CBA_BOX_EQU, 4 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 1 ); - else if ( Type == CBA_BOX_NEQU ) - Vec_IntAddToEntry( vAnds, CBA_BOX_NEQU, 4 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 1 ); - else if ( Type == CBA_BOX_LTHAN ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LTHAN, 6 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 6 ); - else if ( Type == CBA_BOX_MTHAN ) - Vec_IntAddToEntry( vAnds, CBA_BOX_MTHAN, 6 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 6 ); - else if ( Type == CBA_BOX_LETHAN ) - Vec_IntAddToEntry( vAnds, CBA_BOX_LETHAN, 6 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 6 ); - else if ( Type == CBA_BOX_METHAN ) - Vec_IntAddToEntry( vAnds, CBA_BOX_METHAN, 6 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 6 ); - else if ( Type == CBA_BOX_RAND ) - Vec_IntAddToEntry( vAnds, CBA_BOX_RAND, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 1 ); - else if ( Type == CBA_BOX_ROR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_ROR, Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 1 ); - else if ( Type == CBA_BOX_RXOR ) - Vec_IntAddToEntry( vAnds, CBA_BOX_RXOR, 3 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 3 ); - else if ( Type == CBA_BOX_ADD ) - Vec_IntAddToEntry( vAnds, CBA_BOX_ADD, 9 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_SUB ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SUB, 9 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_MUL ) - Vec_IntAddToEntry( vAnds, CBA_BOX_MUL, 9 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 1)) ); - else if ( Type == CBA_BOX_DIV ) - Vec_IntAddToEntry( vAnds, CBA_BOX_DIV, 13 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 19 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) + 10 ); - else if ( Type == CBA_BOX_MOD ) - Vec_IntAddToEntry( vAnds, CBA_BOX_MOD, 13 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 7 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) - 2 ); - else if ( Type == CBA_BOX_POW ) - Vec_IntAddToEntry( vAnds, CBA_BOX_POW, 10 * (int)pow((double)Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)),(double)Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0))) ); - else if ( Type == CBA_BOX_MIN ) - Vec_IntAddToEntry( vAnds, CBA_BOX_MIN, 4 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) ); - else if ( Type == CBA_BOX_SQRT ) - Vec_IntAddToEntry( vAnds, CBA_BOX_SQRT, 11 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) / 8 + 5 * Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)) / 2 - 5 ); - } - if ( nCountRange ) - { - printf( "Warning: %d objects of the design have non-zero-based ranges.\n", nCountRange ); - printf( "In particular, object %6d with name \"%s\" has range %d=[%d:%d]\n", - iRnObj, Cba_FonNameStr(p, Cba_ObjFon0(p, iRnObj)), - Cba_ObjRangeSize(p, iRnObj), Cba_ObjLeft(p, iRnObj), Cba_ObjRight(p, iRnObj) ); - } - // print by occurrence - printf( "ID : name occurrence and2 (occurrence)=. ...\n" ); - for ( i = 0; i < CBA_BOX_LAST; i++ ) - { - Vec_Wrd_t * vType = (Vec_Wrd_t *)Vec_PtrEntry( vTypes, i ); - Vec_Wrd_t * vOccur = (Vec_Wrd_t *)Vec_PtrEntry( vOccurs, i ); - if ( p->pDesign->nObjs[i] == 0 ) - continue; - printf( "%2d : %-8s %6d%8d ", i, pTypeNames[i], p->pDesign->nObjs[i], Vec_IntEntry(vAnds, i) ); - // sort by occurence - Cba_NtkPrintDistribSortOne( vTypes, vOccurs, i ); - Vec_WrdForEachEntry( vType, Sign, k ) - { - Cba_NtkPrintDistribFromSign( Sign, &s, &s0, &s1 ); - if ( ((k % 6) == 5 && s1) || ((k % 8) == 7 && !s1) ) - printf( "\n " ); - printf( "(%d)", (int)Vec_WrdEntry( vOccur, k ) ); - printf( "%s%d", Abc_LitIsCompl(s)?"-":"", Abc_Lit2Var(s) ); - if ( s0 ) - printf( "=%s%d", Abc_LitIsCompl(s0)?"-":"", Abc_Lit2Var(s0) ); - if ( s1 ) - printf( ".%s%d", Abc_LitIsCompl(s1)?"-":"", Abc_Lit2Var(s1) ); - printf( " " ); - } - printf( "\n" ); - } - Vec_VecFree( (Vec_Vec_t *)vTypes ); - Vec_VecFree( (Vec_Vec_t *)vOccurs ); - Vec_IntFree( vAnds ); -} -void Cba_NtkPrintNodes( Cba_Ntk_t * p, int Type ) -{ - int i, iFon0, iFon1, Counter = 0; - char * pTypeNames[CBA_BOX_LAST]; - Cba_ManCreatePrimMap( pTypeNames ); - printf( "Operation %s\n", pTypeNames[Type] ); - Cba_NtkForEachObj( p, i ) - { - if ( (int)Type != Type ) - continue; - iFon0 = Cba_ObjFinFon(p, i, 0); - iFon1 = Cba_ObjFinFon(p, i, 1); - - printf( "%8d :", Counter++ ); - printf( "%8d : ", i ); - printf( "%3d%s = ", Cba_ObjRangeSize(p, i), Cba_ObjSigned(p, i) ? "s" : " " ); - printf( "%3d%s %s ", Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 0)), Cba_ObjSigned(p, iFon0) ? "s" : " ", pTypeNames[Type] ); - printf( "%3d%s ", Cba_ObjRangeSize(p, Cba_ObjFinFon(p, i, 1)), Cba_ObjSigned(p, iFon1) ? "s" : " " ); - printf( " : " ); - printf( "%-12s = ", Cba_ObjNameStr(p, i) ); - printf( "%-12s %s ", Cba_FonIsConst(iFon0) ? Cba_NtkConst(p, Cba_FonConst(iFon0)) : Cba_FonNameStr(p, iFon0), pTypeNames[Type] ); - printf( "%-12s ", Cba_FonIsConst(iFon1) ? Cba_NtkConst(p, Cba_FonConst(iFon1)) : Cba_FonNameStr(p, iFon1) ); - printf( "\n" ); - } -} -void Cba_NtkPrintStatsFull( Cba_Ntk_t * p, int fDistrib, int fVerbose ) -{ - int i; - char * pTypeNames[CBA_BOX_LAST]; - Cba_ManCreatePrimMap( pTypeNames ); - printf( "%-20s : ", Cba_NtkName(p) ); - printf( "PI = %4d ", Cba_NtkPiNum(p) ); - printf( "PO = %4d ", Cba_NtkPoNum(p) ); - printf( "FF = %4d ", Cba_NtkBoxSeqNum(p) ); - printf( "Obj = %6d ", Cba_NtkObjNum(p) ); - printf( "Mem = %.3f MB", 1.0*Cba_NtkMemory(p)/(1<<20) ); - printf( "\n" ); - if ( fDistrib ) - { - Cba_NtkPrintDistrib( p, fVerbose ); - return; - } - if ( !fVerbose ) - return; - printf( "Node type statistics:\n" ); - for ( i = 1; i < CBA_BOX_LAST; i++ ) - { - if ( !p->pDesign->nObjs[i] ) - continue; - if ( p->pDesign->nAnds[0] && p->pDesign->nAnds[i] ) - printf( "%2d : %-8s %6d %7.2f %%\n", i, pTypeNames[i], p->pDesign->nObjs[i], 100.0*p->pDesign->nAnds[i]/p->pDesign->nAnds[0] ); - else - printf( "%2d : %-8s %6d\n", i, pTypeNames[i], p->pDesign->nObjs[i] ); - } -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_NtkCollectDistrib( Cba_Ntk_t * p, int * pCounts, int * pUserCounts ) -{ - int i; - Cba_NtkForEachBox( p, i ) - if ( Cba_ObjIsBoxUser(p, i) ) - pUserCounts[Cba_ObjNtkId(p, i)]++; - else - pCounts[Cba_ObjType(p, i)]++; -} - -void Cba_NtkPrintDistribStat( Cba_Ntk_t * p, int * pCounts, int * pUserCounts ) -{ - Cba_Ntk_t * pNtk; int i; - printf( "Primitives (%d):\n", Cba_NtkBoxPrimNum(p) ); - for ( i = 0; i < CBA_BOX_LAST; i++ ) - if ( pCounts[i] ) - printf( "%-20s = %5d\n", Cba_NtkTypeName(p, i), pCounts[i] ); - printf( "User hierarchy (%d):\n", Cba_NtkBoxUserNum(p) ); - Cba_ManForEachNtk( p->pDesign, pNtk, i ) - if ( pUserCounts[i] ) - printf( "%-20s = %5d\n", Cba_NtkName(pNtk), pUserCounts[i] ); -} -void Cba_NtkPrintDistribOld( Cba_Ntk_t * p ) -{ - int pCounts[CBA_BOX_LAST] = {0}; - int * pUserCounts = ABC_CALLOC( int, Cba_ManNtkNum(p->pDesign) + 1 ); - Cba_ManCreatePrimMap( p->pDesign->pTypeNames ); - Cba_NtkCollectDistrib( p, pCounts, pUserCounts ); - Cba_NtkPrintDistribStat( p, pCounts, pUserCounts ); - ABC_FREE( pUserCounts ); -} - -void Cba_ManPrintDistribStat( Cba_Man_t * p, int * pCounts, int * pUserCounts ) -{ - Cba_Ntk_t * pNtk = Cba_ManRoot(p); int i; - printf( "Primitives:\n" ); - for ( i = 0; i < CBA_BOX_LAST; i++ ) - if ( pCounts[i] ) - printf( "%-20s = %5d\n", Cba_NtkTypeName(pNtk, i), pCounts[i] ); - printf( "User hierarchy:\n" ); - Cba_ManForEachNtk( p, pNtk, i ) - if ( pUserCounts[i] ) - printf( "%-20s = %5d\n", Cba_NtkName(pNtk), pUserCounts[i] ); -} -void Cba_ManPrintDistrib( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - int pCounts[CBA_BOX_LAST] = {0}; - int * pUserCounts = ABC_CALLOC( int, Cba_ManNtkNum(p) + 1 ); - Cba_ManCreatePrimMap( p->pTypeNames ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkCollectDistrib( pNtk, pCounts, pUserCounts ); - Cba_ManPrintDistribStat( p, pCounts, pUserCounts ); - ABC_FREE( pUserCounts ); -} - -/**Function************************************************************* - - Synopsis [Order objects by box type and then by name.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -// compares two numbers with the first mismatching char in i-th position -static inline int Cba_CharIsDigit( char c ) { return c >= '0' && c <= '9'; } -int Cba_StrCmpInt( char * p1, char * p2, int i ) -{ - // check if one of the mismatching chars is a digit - if ( Cba_CharIsDigit(p1[i]) || Cba_CharIsDigit(p2[i]) ) - { - // if previous (equal) char was a digit or if this is first digit on both sides, scroll back - if ( (i > 0 && Cba_CharIsDigit(p1[i-1])) || (Cba_CharIsDigit(p1[i]) && Cba_CharIsDigit(p2[i])) ) - { - int Num1, Num2; - // find the first digit - for ( --i; i >= 0; i-- ) - if ( !Cba_CharIsDigit(p1[i]) ) - break; - i++; - // current char is digit - assert( Cba_CharIsDigit(p1[i]) ); - assert( Cba_CharIsDigit(p2[i]) ); - // previous char does not exist or is not a digit - assert( i == 0 || !Cba_CharIsDigit(p1[i-1]) ); - assert( i == 0 || !Cba_CharIsDigit(p2[i-1]) ); - // compare numbers - Num1 = atoi( p1 + i ); - Num2 = atoi( p2 + i ); - if ( Num1 < Num2 ) - return -1; - if ( Num1 > Num2 ) - return 1; - assert( 0 ); - return 0; - } - } - // compare as usual - if ( p1[i] < p2[i] ) - return -1; - if ( p1[i] > p2[i] ) - return 1; - assert( 0 ); - return 0; -} -int Cba_StrCmp( char ** pp1, char ** pp2 ) -{ - char * p1 = *pp1; - char * p2 = *pp2; int i; - for ( i = 0; p1[i] && p2[i]; i++ ) - if ( p1[i] != p2[i] ) - return Cba_StrCmpInt( p1, p2, i ); - assert( !p1[i] || !p2[i] ); - return Cba_StrCmpInt( p1, p2, i ); -} -void Cba_NtkObjOrder( Cba_Ntk_t * p, Vec_Int_t * vObjs, Vec_Int_t * vNameIds ) -{ - char Buffer[1000], * pName; - Vec_Ptr_t * vNames; - int i, iObj; - if ( Vec_IntSize(vObjs) < 2 ) - return; - vNames = Vec_PtrAlloc( Vec_IntSize(vObjs) ); - Vec_IntForEachEntry( vObjs, iObj, i ) - { - char * pTypeName = Cba_NtkTypeName( p, Cba_ObjType(p, iObj) ); - char * pInstName = vNameIds ? Cba_NtkStr(p, Vec_IntEntry(vNameIds, i)) : Cba_ObjNameStr(p, iObj); - sprintf( Buffer, "%s_%s_%d", pTypeName, pInstName, iObj ); - Vec_PtrPush( vNames, Abc_UtilStrsav(Buffer) ); - } - // print before -// Vec_PtrForEachEntry( char *, vNames, pName, i ) -// printf( "%s \n", pName ); -// printf( "\n" ); - // do the sorting - Vec_PtrSort( vNames, (int (*)(const void *, const void *))Cba_StrCmp ); - // print after -// Vec_PtrForEachEntry( char *, vNames, pName, i ) -// printf( "%s \n", pName ); -// printf( "\n" ); - // reload in a new order - Vec_IntClear( vObjs ); - Vec_PtrForEachEntry( char *, vNames, pName, i ) - Vec_IntPush( vObjs, atoi(strrchr(pName, '_')+1) ); - Vec_PtrFreeFree( vNames ); -} - - -/**Function************************************************************* - - Synopsis [Returns the number of CI fons.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_NtkCiFonNum( Cba_Ntk_t * p ) -{ - int i, iObj, Count = Cba_NtkPiNum(p); - Cba_NtkForEachBoxSeq( p, iObj, i ) - Count += Cba_ObjFonNum(p, iObj); - return Count; -} -int Cba_NtkCoFinNum( Cba_Ntk_t * p ) -{ - int i, iObj, Count = Cba_NtkPoNum(p); - Cba_NtkForEachBoxSeq( p, iObj, i ) - Count += Cba_ObjFinNum(p, iObj); - return Count; -} - -/**Function************************************************************* - - Synopsis [Returns 1 if the manager is in the topo order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_NtkIsTopoOrder( Cba_Ntk_t * p ) -{ - int i, k, iObj, iFin, iFanin, fTopo = 1; - Vec_Bit_t * vVisited = Vec_BitStart( Cba_NtkObjNum(p) + 1 ); - // mark PIs and seq objects - Cba_NtkForEachPi( p, iObj, i ) - Vec_BitWriteEntry( vVisited, iObj, 1 ); - Cba_NtkForEachBoxSeq( p, iObj, i ) - Vec_BitWriteEntry( vVisited, iObj, 1 ); - // visit combinational nodes - Cba_NtkForEachBox( p, iObj ) - if ( !Cba_ObjIsSeq(p, iObj) ) - { - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - if ( !Vec_BitEntry(vVisited, iFanin) ) - fTopo = 0; - if ( !fTopo ) - break; - Vec_BitWriteEntry( vVisited, iObj, 1 ); - } - // visit POs and seq objects - if ( fTopo ) - Cba_NtkForEachPo( p, iObj, i ) - { - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - if ( !Vec_BitEntry(vVisited, iFanin) ) - fTopo = 0; - if ( !fTopo ) - break; - } - if ( fTopo ) - Cba_NtkForEachBoxSeq( p, iObj, i ) - { - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - if ( !Vec_BitEntry(vVisited, iFanin) ) - fTopo = 0; - if ( !fTopo ) - break; - } - Vec_BitFree( vVisited ); - return fTopo; -} -int Cba_ManIsTopoOrder( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - Cba_ManForEachNtk( p, pNtk, i ) - if ( !Cba_NtkIsTopoOrder(pNtk) ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Collects user boxes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_NtkCheckComboLoop_rec( Cba_Ntk_t * p, int iObj ) -{ - int k, iFin, iFanin; - if ( Cba_ObjIsPi(p, iObj) ) - return 1; - if ( Cba_ObjCopy(p, iObj) == 1 ) // visited - return 1; - if ( Cba_ObjCopy(p, iObj) == 0 ) // loop - return 0; - Cba_ObjSetCopy( p, iObj, 0 ); - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - if ( !Cba_ObjIsSeq(p, iFanin) ) - if ( !Cba_NtkCheckComboLoop_rec( p, iFanin ) ) - return 0; - //Cba_ObjSetCopy( p, iObj, 1 ); - Vec_IntSetEntry( &p->vObjCopy, iObj, 1 ); - return 1; -} -int Cba_NtkCheckComboLoop( Cba_Ntk_t * p ) -{ - int iObj; - Cba_NtkCleanObjCopies( p ); // -1 = not visited; 0 = on the path; 1 = finished - Cba_NtkForEachBox( p, iObj ) - if ( !Cba_ObjIsSeq(p, iObj) ) - if ( !Cba_NtkCheckComboLoop_rec( p, iObj ) ) - { - printf( "Cyclic dependency of user boxes is detected.\n" ); - return 0; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Find one missing object.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Cba_NtkFindMissing( Vec_Int_t * vObjs, int nObjs ) -{ - Vec_Int_t * vMap = Vec_IntStartFull( nObjs + 1 ); - int i, iObj; - Vec_IntForEachEntry( vObjs, iObj, i ) - Vec_IntWriteEntry( vMap, iObj, i ); - Vec_IntForEachEntryStart( vMap, i, iObj, 1 ) - if ( i == -1 ) - { - Vec_IntFree( vMap ); - return iObj; - } - Vec_IntFree( vMap ); - return -1; -} - -/**Function************************************************************* - - Synopsis [Collect nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_NtkCollectDfs_rec( Cba_Ntk_t * p, int iObj, Vec_Int_t * vObjs ) -{ - int iFin, iFanin, k; - if ( !Cba_ObjCopy(p, iObj) ) - return; - Cba_ObjSetCopy( p, iObj, 0 ); - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - Vec_IntPush( vObjs, iObj ); -} -Vec_Int_t * Cba_NtkCollectDfs( Cba_Ntk_t * p ) -{ - int i, k, iObj, iFin, iFanin; - Vec_Int_t * vObjs = Vec_IntAlloc( Cba_NtkObjNum(p) ); - // collect PIs and seq boxes - Cba_NtkForEachPi( p, iObj, i ) - Vec_IntPush( vObjs, iObj ); - Cba_NtkForEachBoxSeq( p, iObj, i ) - Vec_IntPush( vObjs, iObj ); - // prepare leaves - Cba_NtkCleanObjCopies( p ); - Vec_IntForEachEntry( vObjs, iObj, i ) - Cba_ObjSetCopy( p, iObj, 0 ); - // collect internal - Cba_NtkForEachPo( p, iObj, i ) - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - Cba_NtkForEachBoxSeq( p, iObj, i ) - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - // collect POs - Cba_NtkForEachPo( p, iObj, i ) - Vec_IntPush( vObjs, iObj ); - assert( Vec_IntSize(vObjs) <= Cba_NtkObjNum(p) ); - if ( Vec_IntSize(vObjs) != Cba_NtkObjNum(p) && !Abc_FrameReadFlag("silentmode") ) - { - int iObj = Cba_NtkFindMissing( vObjs, Cba_NtkObjNum(p) ); - printf( "Warning: DSF ordering for module \"%s\" collected %d out of %d objects.\n", Cba_NtkName(p), Vec_IntSize(vObjs), Cba_NtkObjNum(p) ); - printf( " For example, object %d with name \"%s\" is not reachable from outputs.\n", - iObj, iObj > 0 ? Cba_FonNameStr( p, Cba_ObjFon0(p, iObj) ) : "" ); - } - return vObjs; -} - - -/**Function************************************************************* - - Synopsis [Count number of objects after collapsing.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_ManGetClpStats_rec( Cba_Ntk_t * p, int * pCountN, int * pCountI, int * pCountO ) -{ - int iObj, Id = Cba_NtkId(p); - if ( pCountN[Id] >= 0 ) - return; - pCountN[Id] = pCountI[Id] = pCountO[Id] = 0; - Cba_NtkForEachObj( p, iObj ) - if ( Cba_ObjIsBoxPrim(p, iObj) ) - { - pCountN[Id] += 1; - pCountI[Id] += Cba_ObjFinNum(p, iObj); - pCountO[Id] += Cba_ObjFonNum(p, iObj); - } - else if ( Cba_ObjIsBoxUser(p, iObj) ) - { - int NtkId = Cba_ObjNtkId(p, iObj); - Cba_ManGetClpStats_rec( Cba_ObjNtk(p, iObj), pCountN, pCountI, pCountO ); - pCountN[Id] += pCountN[NtkId] + Cba_ObjFonNum(p, iObj); - pCountI[Id] += pCountI[NtkId] + Cba_ObjFonNum(p, iObj); - pCountO[Id] += pCountO[NtkId] + Cba_ObjFonNum(p, iObj); - } -} -void Cba_ManGetClpStats( Cba_Man_t * p, int * nObjs, int * nFins, int * nFons ) -{ - int * pCountN = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); - int * pCountI = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); - int * pCountO = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); - Cba_Ntk_t * pRoot = Cba_ManRoot(p); - Cba_ManGetClpStats_rec( pRoot, pCountN, pCountI, pCountO ); - *nObjs = Cba_NtkPioNum(pRoot) + pCountN[Cba_NtkId(pRoot)]; - *nFins = Cba_NtkPoNum(pRoot) + pCountI[Cba_NtkId(pRoot)]; - *nFons = Cba_NtkPiNum(pRoot) + pCountO[Cba_NtkId(pRoot)]; - ABC_FREE( pCountN ); - ABC_FREE( pCountI ); - ABC_FREE( pCountO ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_NtkCollapse_rec( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, iObj, iObjNew, iFin, iFon; - Cba_NtkCleanObjCopies( p ); - Cba_NtkCleanFonCopies( p ); - // set PI copies - assert( Vec_IntSize(vSigs) == Cba_NtkPiNum(p) ); - Cba_NtkForEachPiFon( p, iObj, iFon, i ) - Cba_FonSetCopy( p, iFon, Vec_IntEntry(vSigs, i) ); - // duplicate primitives and create buffers for user instances - Cba_NtkForEachObj( p, iObj ) - if ( Cba_ObjIsBoxPrim( p, iObj ) ) - { - iObjNew = Cba_ObjDup( pNew, p, iObj ); - Cba_ObjForEachFon( p, iObj, iFon, i ) - Cba_FonSetCopy( p, iFon, Cba_ObjFon(pNew, iObjNew, i) ); - if ( Cba_ObjAttr(p, iObj) ) - Cba_ObjSetAttrs( pNew, iObjNew, Cba_ObjAttrArray(p, iObj), Cba_ObjAttrSize(p, iObj) ); - } - else if ( Cba_ObjIsBoxUser( p, iObj ) ) - { - Cba_ObjForEachFon( p, iObj, iFon, i ) - { - iObjNew = Cba_ObjAlloc( pNew, CBA_BOX_BUF, 1, 1 ); - Cba_FonSetCopy( p, iFon, Cba_ObjFon0(pNew, iObjNew) ); - } - } - // connect primitives and collapse user instances - Cba_NtkForEachObj( p, iObj ) - if ( Cba_ObjIsBoxPrim( p, iObj ) ) - { - iObjNew = Cba_ObjCopy( p, iObj ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) - Cba_ObjSetFinFon( pNew, iObjNew, i, Cba_FonCopy(p, iFon) ); - } - else if ( Cba_ObjIsBoxUser( p, iObj ) ) - { - Vec_IntClear( vSigs ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) - Vec_IntPush( vSigs, Cba_FonCopy(p, iFon) ); - assert( Vec_IntSize(vSigs) == Cba_ObjFinNum(p, iObj) ); - Cba_NtkCollapse_rec( pNew, Cba_ObjNtk(p, iObj), vSigs ); - assert( Vec_IntSize(vSigs) == Cba_ObjFonNum(p, iObj) ); - Cba_ObjForEachFon( p, iObj, iFon, i ) - { - iObjNew = Cba_FonObj( pNew, Cba_FonCopy(p, iFon) ); // buffer - Cba_ObjSetFinFon( pNew, iObjNew, 0, Vec_IntEntry(vSigs, i) ); - } - } - // collect POs - Vec_IntClear( vSigs ); - Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) - Vec_IntPush( vSigs, Cba_FonCopy(p, iFon) ); -} -Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p ) -{ - Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24), Hash_IntManRef(p->vHash) ); - Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew; - Vec_Int_t * vSigs = Vec_IntAlloc( 1000 ); - int i, iObj, iObjNew, iFon, nObjs = 0, nFins = 0, nFons = 0; - Cba_ManDupTypeNames( pNew, p ); - Cba_ManGetClpStats( p, &nObjs, &nFins, &nFons ); - pRootNew = Cba_NtkAlloc( pNew, Cba_NtkNameId(pRoot), Cba_NtkPiNum(pRoot), Cba_NtkPoNum(pRoot), nObjs, nFins, nFons ); - Cba_NtkAdd( pNew, pRootNew ); - if ( Cba_NtkHasObjNames(pRoot) ) - Cba_NtkCleanObjNames( pRootNew ); - if ( Cba_NtkHasFonNames(pRoot) ) - Cba_NtkCleanFonNames( pRootNew ); - if ( Cba_NtkHasObjAttrs(pRoot) ) - Cba_NtkCleanObjAttrs( pRootNew ); - if ( Cba_ObjAttr(pRoot, 0) ) - Cba_ObjSetAttrs( pRootNew, 0, Cba_ObjAttrArray(pRoot, 0), Cba_ObjAttrSize(pRoot, 0) ); - Cba_NtkCleanObjCopies( pRoot ); - Cba_NtkForEachPiFon( pRoot, iObj, iFon, i ) - { - iObjNew = Cba_ObjDup( pRootNew, pRoot, iObj ); - Vec_IntPush( vSigs, Cba_ObjFon0(pRootNew, iObjNew) ); - if ( Cba_NtkHasObjNames(pRoot) ) - Cba_ObjSetName( pRootNew, iObjNew, Cba_ObjName(pRoot, iObj) ); - if ( Cba_NtkHasFonNames(pRoot) ) - Cba_FonSetName( pRootNew, Cba_ObjFon0(pRootNew, iObjNew), Cba_FonName(pRoot, iFon) ); - if ( Cba_ObjAttr(pRoot, iObj) ) - Cba_ObjSetAttrs( pRootNew, iObjNew, Cba_ObjAttrArray(pRoot, iObj), Cba_ObjAttrSize(pRoot, iObj) ); - } - assert( Vec_IntSize(vSigs) == Cba_NtkPiNum(pRoot) ); - Cba_NtkCollapse_rec( pRootNew, pRoot, vSigs ); - assert( Vec_IntSize(vSigs) == Cba_NtkPoNum(pRoot) ); - Cba_NtkForEachPoDriverFon( pRoot, iObj, iFon, i ) - { - iObjNew = Cba_ObjDup( pRootNew, pRoot, iObj ); - Cba_ObjSetFinFon( pRootNew, iObjNew, 0, Vec_IntEntry(vSigs, i) ); - if ( Cba_NtkHasObjNames(pRoot) ) - Cba_ObjSetName( pRootNew, iObjNew, Cba_ObjName(pRoot, iObj) ); - if ( Cba_NtkHasFonNames(pRoot) ) - Cba_FonSetName( pRootNew, Vec_IntEntry(vSigs, i), Cba_FonName(pRoot, iFon) ); - if ( Cba_ObjAttr(pRoot, iObj) ) - Cba_ObjSetAttrs( pRootNew, iObjNew, Cba_ObjAttrArray(pRoot, iObj), Cba_ObjAttrSize(pRoot, iObj) ); - } - Vec_IntFree( vSigs ); - assert( Cba_NtkObjNum(pRootNew) == Cba_NtkObjNumAlloc(pRootNew) ); - assert( Cba_NtkFinNum(pRootNew) == Cba_NtkFinNumAlloc(pRootNew) ); - assert( Cba_NtkFonNum(pRootNew) == Cba_NtkFonNumAlloc(pRootNew) ); - // create internal node names - Cba_NtkMissingFonNames( pRootNew, "m" ); - //Cba_NtkPrepareSeq( pRootNew ); - return pNew; -} - - - -/**Function************************************************************* - - Synopsis [Performs the reverse of collapsing.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Int_t * Cba_NtkCollectInFons( Cba_Ntk_t * p, Vec_Int_t * vObjs ) -{ - Vec_Int_t * vFons = Vec_IntAlloc( 100 ); - Vec_Bit_t * vVisFons = Vec_BitStart( Cba_NtkFonNum(p) + 1 ); - int i, k, iObj, iFin, iFon, Entry; - // mark fanin fons - Vec_IntForEachEntry( vObjs, iObj, i ) - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - if ( iFon > 0 ) - Vec_BitWriteEntry( vVisFons, iFon, 1 ); - // unmark internal fons - Vec_IntForEachEntry( vObjs, iObj, i ) - Cba_ObjForEachFon( p, iObj, iFon, k ) - Vec_BitWriteEntry( vVisFons, iFon, 0 ); - // collect fons - Vec_BitForEachEntry( vVisFons, Entry, iFon ) - if ( Entry ) - Vec_IntPush( vFons, iFon ); - Vec_BitFree( vVisFons ); - return vFons; -} -Vec_Int_t * Cba_NtkCollectOutFons( Cba_Ntk_t * p, Vec_Int_t * vObjs ) -{ - Vec_Int_t * vFons = Vec_IntAlloc( 100 ); - Vec_Bit_t * vMapObjs = Vec_BitStart( Cba_NtkObjNum(p) + 1 ); - Vec_Bit_t * vVisFons = Vec_BitStart( Cba_NtkFonNum(p) + 1 ); - int i, k, iObj, iFin, iFon; - // map objects - Vec_IntForEachEntry( vObjs, iObj, i ) - Vec_BitWriteEntry( vMapObjs, iObj, 1 ); - // mark those used by non-objects - Cba_NtkForEachObj( p, iObj ) - if ( !Vec_BitEntry(vMapObjs, iObj) ) - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - if ( iFon > 0 ) - Vec_BitWriteEntry( vVisFons, iFon, 1 ); - // collect pointed fons among those in objects - Vec_IntForEachEntry( vObjs, iObj, i ) - Cba_ObjForEachFon( p, iObj, iFon, k ) - if ( Vec_BitEntry(vVisFons, iFon) ) - Vec_IntPush( vFons, iFon ); - Vec_BitFree( vMapObjs ); - Vec_BitFree( vVisFons ); - return vFons; -} -void Cba_NtkCollectGroupStats( Cba_Ntk_t * p, Vec_Int_t * vObjs, int * pnFins, int * pnFons ) -{ - int i, iObj, nFins = 0, nFons = 0; - Vec_IntForEachEntry( vObjs, iObj, i ) - { - nFins += Cba_ObjFinNum(p, iObj); - nFons += Cba_ObjFonNum(p, iObj); - } - *pnFins = nFins; - *pnFons = nFons; -} -void Cba_ManExtractGroupInt( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vObjs, Vec_Int_t * vFonIns, Vec_Int_t * vFonOuts ) -{ - int i, k, iObj, iObjNew, iFin, iFon; - Cba_NtkCleanObjCopies( p ); - Cba_NtkCleanFonCopies( p ); - // create inputs and map fons - Vec_IntForEachEntry( vFonIns, iFon, i ) - { - iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_PI, 0, 1 ); - Cba_FonSetCopy( p, iFon, Cba_ObjFon0(pNew, iObjNew) ); - if ( Cba_NtkHasObjNames(p) ) - Cba_ObjSetName( pNew, iObjNew, Cba_ObjName(p, Cba_FonObj(p, iFon)) ); - if ( Cba_NtkHasFonNames(p) ) - Cba_FonSetName( pNew, Cba_ObjFon0(pNew, iObjNew), Cba_FonName(p, iFon) ); - - } - // create internal - Vec_IntForEachEntry( vObjs, iObj, i ) - { - iObjNew = Cba_ObjDup( pNew, p, iObj ); - if ( Cba_NtkHasObjNames(p) ) - Cba_ObjSetName( pNew, iObjNew, Cba_ObjName(p, iObj) ); - Cba_ObjForEachFon( p, iObj, iFon, k ) - { - Cba_FonSetCopy( p, iFon, Cba_ObjFon(pNew, iObjNew, k) ); - if ( Cba_NtkHasFonNames(p) ) - Cba_FonSetName( pNew, Cba_ObjFon(pNew, iObjNew, k), Cba_FonName(p, iFon) ); - } - } - // connect internal - Vec_IntForEachEntry( vObjs, iObj, i ) - { - iObjNew = Cba_ObjCopy( p, iObj ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) - Cba_ObjSetFinFon( pNew, iObjNew, k, Cba_FonCopy(p, iFon) ); - } - // create POs - Vec_IntForEachEntry( vFonOuts, iFon, i ) - { - iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_PO, 1, 0 ); - if ( Cba_NtkHasObjNames(p) ) - Cba_ObjSetName( pNew, iObjNew, Cba_FonName(p, iFon) ); - Cba_ObjSetFinFon( pNew, iObjNew, 0, Cba_FonCopy(p, iFon) ); - } - assert( Cba_NtkObjNum(pNew) == Cba_NtkObjNumAlloc(pNew) ); - assert( Cba_NtkFinNum(pNew) == Cba_NtkFinNumAlloc(pNew) ); - assert( Cba_NtkFonNum(pNew) == Cba_NtkFonNumAlloc(pNew) ); -} -Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs ) -{ - Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24), Hash_IntManRef(p->vHash) ); - Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew; - Vec_Int_t * vFonIns = Cba_NtkCollectInFons( pRoot, vObjs ); - Vec_Int_t * vFonOuts = Cba_NtkCollectOutFons( pRoot, vObjs ); - int nObjs, nFins, nFons; - Cba_ManDupTypeNames( pNew, p ); - // collect stats - Cba_NtkCollectGroupStats( pRoot, vObjs, &nFins, &nFons ); - nObjs = Vec_IntSize(vObjs) + Vec_IntSize(vFonIns) + Vec_IntSize(vFonOuts); - nFins += Vec_IntSize(vFonOuts); - nFons += Vec_IntSize(vFonIns); - // create network - pRootNew = Cba_NtkAlloc( pNew, Cba_NtkNameId(pRoot), Vec_IntSize(vFonIns), Vec_IntSize(vFonOuts), nObjs, nFins, nFons ); - Cba_NtkAdd( pNew, pRootNew ); - if ( Cba_NtkHasObjNames(pRoot) ) - Cba_NtkCleanObjNames( pRootNew ); - if ( Cba_NtkHasFonNames(pRoot) ) - Cba_NtkCleanFonNames( pRootNew ); - // add group nodes - Cba_ManExtractGroupInt( pRootNew, pRoot, vObjs, vFonIns, vFonOuts ); - Cba_NtkMissingFonNames( pRootNew, "b" ); - //Cba_NtkPrepareSeq( pRootNew ); - // cleanup - Vec_IntFree( vFonIns ); - Vec_IntFree( vFonOuts ); - return pNew; -} - - -/**Function************************************************************* - - Synopsis [Derives the design from the GIA manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Cba_NtkInsertGiaLit( Cba_Ntk_t * p, int iLit, Vec_Int_t * vLit2Fon, int fUseXor ) -{ - int iObjNew; - if ( iLit == 0 || iLit == 1 ) - return Cba_FonFromConst(iLit); - if ( Vec_IntEntry(vLit2Fon, iLit) >= 0 ) - return Vec_IntEntry(vLit2Fon, iLit); - assert( Abc_LitIsCompl(iLit) ); - assert( Vec_IntEntry(vLit2Fon, Abc_LitNot(iLit)) >= 0 ); - // create inverter - if ( fUseXor ) - { - iObjNew = Cba_ObjAlloc( p, CBA_BOX_XOR, 2, 1 ); - Cba_ObjSetFinFon( p, iObjNew, 0, Vec_IntEntry(vLit2Fon, Abc_LitNot(iLit)) ); - Cba_ObjSetFinFon( p, iObjNew, 1, Cba_FonFromConst(1) ); - } - else - { - iObjNew = Cba_ObjAlloc( p, CBA_BOX_INV, 1, 1 ); - Cba_ObjSetFinFon( p, iObjNew, 0, Vec_IntEntry(vLit2Fon, Abc_LitNot(iLit)) ); - } - // save the result - Vec_IntWriteEntry( vLit2Fon, iLit, Cba_ObjFon0(p, iObjNew) ); - return Cba_ObjFon0(p, iObjNew); -} -static inline int Cba_NtkInsertGiaObj( Cba_Ntk_t * p, Gia_Man_t * pGia, int iObj, Vec_Int_t * vLit2Fon, int fUseXor ) -{ - Gia_Obj_t * pObj = Gia_ManObj( pGia, iObj ); - int iLit0 = Gia_ObjFaninLit0( pObj, iObj ); - int iLit1 = Gia_ObjFaninLit1( pObj, iObj ); - int iFon0 = Cba_NtkInsertGiaLit( p, iLit0, vLit2Fon, fUseXor ); - int iFon1 = Cba_NtkInsertGiaLit( p, iLit1, vLit2Fon, fUseXor ); - int iObjNew; - if ( Gia_ObjIsMux(pGia, pObj) ) - { - int iLit2 = Gia_ObjFaninLit2( pGia, iObj ); - int iFon2 = Cba_NtkInsertGiaLit( p, iLit2, vLit2Fon, fUseXor ); - iObjNew = Cba_ObjAlloc( p, CBA_BOX_MUX, 3, 1 ); - Cba_ObjSetFinFon( p, iObjNew, 0, iFon2 ); - Cba_ObjSetFinFon( p, iObjNew, 1, iFon1 ); - Cba_ObjSetFinFon( p, iObjNew, 2, iFon0 ); - } - else - { - assert( Gia_ObjIsAnd(pObj) ); - iObjNew = Cba_ObjAlloc( p, Gia_ObjIsXor(pObj) ? CBA_BOX_XOR : CBA_BOX_AND, 2, 1 ); - Cba_ObjSetFinFon( p, iObjNew, 0, iFon0 ); - Cba_ObjSetFinFon( p, iObjNew, 1, iFon1 ); - } - Vec_IntWriteEntry( vLit2Fon, Abc_Var2Lit(iObj, 0), Cba_ObjFon0(p, iObjNew) ); - return iObjNew; -} -Cba_Man_t * Cba_ManDeriveFromGia( Cba_Man_t * pOld, Gia_Man_t * pGia, int fUseXor ) -{ - Cba_Man_t * p = Cba_ManAlloc( pGia->pSpec, 1, pOld ? Abc_NamRef(pOld->pStrs) : NULL, pOld ? Abc_NamRef(pOld->pFuns) : NULL, NULL, NULL ); - Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, Abc_NamStrFindOrAdd(p->pStrs, pGia->pName, NULL), Gia_ManCiNum(pGia), Gia_ManCoNum(pGia), 1000, 2000, 2000 ); - Vec_Int_t * vLit2Fon = Vec_IntStartFull( 2*Gia_ManObjNum(pGia) ); - int i, iObj, iObjNew, NameId, iLit0, iFon0; - Gia_Obj_t * pObj; - //Cba_ManPrepareTypeNames( p ); - Cba_NtkAdd( p, pNtk ); - Cba_NtkCleanObjNames( pNtk ); - Gia_ManForEachCiId( pGia, iObj, i ) - { - NameId = pGia->vNamesIn? Abc_NamStrFindOrAdd(p->pStrs, (char*)Vec_PtrEntry(pGia->vNamesIn, i), NULL) : Cba_NtkNewStrId(pNtk, "i%d", i); - iObjNew = Cba_ObjAlloc( pNtk, CBA_OBJ_PI, 0, 1 ); - Cba_ObjSetName( pNtk, iObjNew, NameId ); - Vec_IntWriteEntry( vLit2Fon, Abc_Var2Lit(iObj, 0), Cba_ObjFon0(pNtk, iObjNew) ); - } - Gia_ManForEachAndId( pGia, iObj ) - Cba_NtkInsertGiaObj( pNtk, pGia, iObj, vLit2Fon, fUseXor ); - // create inverters if needed - Gia_ManForEachCoId( pGia, iObj, i ) - { - pObj = Gia_ManObj( pGia, iObj ); - iLit0 = Gia_ObjFaninLit0( pObj, iObj ); - iFon0 = Cba_NtkInsertGiaLit( pNtk, iLit0, vLit2Fon, fUseXor ); // can be const! - } - Gia_ManForEachCoId( pGia, iObj, i ) - { - pObj = Gia_ManObj( pGia, iObj ); - iLit0 = Gia_ObjFaninLit0( pObj, iObj ); - iFon0 = Cba_NtkInsertGiaLit( pNtk, iLit0, vLit2Fon, fUseXor ); // can be const! - iObjNew = Cba_ObjAlloc( pNtk, CBA_BOX_BUF, 1, 1 ); - Cba_ObjSetFinFon( pNtk, iObjNew, 0, iFon0 ); - iFon0 = Cba_ObjFon0(pNtk, iObjNew); // non-const fon unique for this output - NameId = pGia->vNamesOut? Abc_NamStrFindOrAdd(p->pStrs, (char*)Vec_PtrEntry(pGia->vNamesOut, i), NULL) : Cba_NtkNewStrId(pNtk, "o%d", i); - iObjNew = Cba_ObjAlloc( pNtk, CBA_OBJ_PO, 1, 0 ); - Cba_ObjSetName( pNtk, iObjNew, NameId ); - Cba_ObjSetFinFon( pNtk, iObjNew, 0, iFon0 ); - } - Cba_NtkCleanFonNames( pNtk ); - Cba_NtkCreateFonNames( pNtk, "a" ); - Vec_IntFree( vLit2Fon ); - return p; -} - - -/**Function************************************************************* - - Synopsis [Inserts the network into the root module instead of objects.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_NtkInsertGroup( Cba_Ntk_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ) -{ - Vec_Int_t * vFonIns = Cba_NtkCollectInFons( p, vObjs ); - Vec_Int_t * vFonOuts = Cba_NtkCollectOutFons( p, vObjs ); - int k, iObj, iObjNew, iFin, iFon; - assert( Cba_NtkPiNum(pSyn) == Vec_IntSize(vFonIns) ); - assert( Cba_NtkPoNum(pSyn) == Vec_IntSize(vFonOuts) ); - // mark AIG with the input fons - Cba_NtkCleanFonCopies( pSyn ); - Cba_NtkForEachPiFon( pSyn, iObj, iFon, k ) - Cba_FonSetCopy( pSyn, iFon, Vec_IntEntry(vFonIns, k) ); - Vec_IntFree( vFonIns ); - // build up internal nodes - Cba_NtkCleanObjCopies( pSyn ); - Cba_NtkForEachBox( pSyn, iObj ) - { - iObjNew = Cba_ObjDup( p, pSyn, iObj ); - Cba_ObjForEachFon( pSyn, iObj, iFon, k ) - Cba_FonSetCopy( pSyn, iFon, Cba_ObjFon(p, iObjNew, k) ); - } - // connect internal nodes - Cba_NtkForEachBox( pSyn, iObj ) - { - iObjNew = Cba_ObjCopy( pSyn, iObj ); - Cba_ObjForEachFinFon( pSyn, iObj, iFin, iFon, k ) - Cba_ObjSetFinFon( p, iObjNew, k, Cba_FonCopy(pSyn, iFon) ); - } - // connect output fons - Cba_NtkCleanFonCopies( p ); - if ( Cba_NtkHasFonNames(p) ) - Vec_IntFillExtra( &p->vFonName, Cba_NtkFonNum(p) + 1, 0 ); - Cba_NtkForEachPoDriverFon( pSyn, iObj, iFon, k ) - { - assert( Cba_FonIsReal(Cba_FonCopy(pSyn, iFon)) ); - Cba_FonSetCopy( p, Vec_IntEntry(vFonOuts, k), Cba_FonCopy(pSyn, iFon) ); - // transfer names - if ( Cba_NtkHasFonNames(p) ) - { - Cba_FonSetName( p, Cba_FonCopy(pSyn, iFon), Cba_FonName(p, Vec_IntEntry(vFonOuts, k)) ); - Cba_FonCleanName( p, Vec_IntEntry(vFonOuts, k) ); - } - } - Vec_IntFree( vFonOuts ); - // delete nodes -// Vec_IntForEachEntry( vObjs, iObj, k ) -// Cba_ObjDelete( p, iObj ); - // update fins pointing to output fons to point to the new fons - Cba_NtkForEachFinFon( p, iFon, iFin ) - if ( Cba_FonIsReal(iFon) && Cba_FonCopy(p, iFon) ) - Cba_PatchFinFon( p, iFin, Cba_FonCopy(p, iFon) ); - Cba_NtkMissingFonNames( p, "j" ); -/* - // duplicate in DFS order - pNew = Cba_NtkDupOrder( p->pDesign, p, Cba_NtkCollectDfs ); - Cba_NtkDupAttrs( pNew, p ); - // replace "p" with "pNew" - Cba_NtkUpdate( Cba_NtkMan(p), pNew ); // removes "p" - return pNew; -*/ -} -Cba_Man_t * Cba_ManInsertGroup( Cba_Man_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ) -{ - Cba_NtkInsertGroup( Cba_ManRoot(p), vObjs, pSyn ); - Cba_NtkCheckComboLoop( Cba_ManRoot(p) ); - return Cba_ManDup( p, Cba_NtkCollectDfs ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaPrs.h b/src/base/cba/cbaPrs.h deleted file mode 100644 index 6a259ccd2..000000000 --- a/src/base/cba/cbaPrs.h +++ /dev/null @@ -1,520 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaPrs.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Parser declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaPrs.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef ABC__base__prs__prs_h -#define ABC__base__prs__prs_h - - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include "aig/gia/gia.h" -#include "misc/util/utilNam.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -// Verilog keywords -typedef enum { - PRS_VER_NONE = 0, // 0: unused - PRS_VER_INPUT, // 1: input - PRS_VER_OUTPUT, // 2: output - PRS_VER_INOUT, // 3: inout - PRS_VER_WIRE, // 4: wire - PRS_VER_REG, // 5: reg - PRS_VER_MODULE, // 6: module - PRS_VER_ASSIGN, // 7: assign - PRS_VER_ALWAYS, // 8: always - PRS_VER_FUNCTION, // 9: function - PRS_VER_DEFPARAM, // 10: defparam - PRS_VER_BEGIN, // 11: begin - PRS_VER_END, // 12: end - PRS_VER_CASE, // 13: case - PRS_VER_ENDCASE, // 14: endcase - PRS_VER_SIGNED, // 15: signed - PRS_VER_ENDMODULE, // 16: endmodule - PRS_VER_UNKNOWN // 17: unknown -} Cba_VerType_t; - -// parser name types -typedef enum { - CBA_PRS_NAME = 0, // 0: name/variable - CBA_PRS_SLICE, // 1: slice - CBA_PRS_CONST, // 2: constant - CBA_PRS_CONCAT, // 3: concatentation -} Prs_ManType_t; - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -// network -typedef struct Prs_Ntk_t_ Prs_Ntk_t; -struct Prs_Ntk_t_ -{ - // general info - int iModuleName; - unsigned fMapped : 1; - unsigned fSlices : 1; - unsigned fHasC0s : 1; - unsigned fHasC1s : 1; - unsigned fHasCXs : 1; - unsigned fHasCZs : 1; - Abc_Nam_t * pStrs; - Abc_Nam_t * pFuns; - Hash_IntMan_t * vHash; - // interface - Vec_Int_t vOrder; // order of signals - // signal names - Vec_Int_t vInouts; // inouts - Vec_Int_t vInputs; // inputs - Vec_Int_t vOutputs; // outputs - Vec_Int_t vWires; // wires - // signal ranges - Vec_Int_t vInoutsR; // inouts - Vec_Int_t vInputsR; // inputs - Vec_Int_t vOutputsR; // outputs - Vec_Int_t vWiresR; // wires - // slices/concatenations/objects - Vec_Int_t vSlices; // NameId + RangeId - Vec_Int_t vConcats; // array of NameId/SliceId/ConstId - Vec_Int_t vBoxes; // ModuleId + InstId + array of pairs {FormNameId, ActSignalId(NameId/SliceId/ConstId/ConcatId)} - Vec_Int_t vObjs; // box handles -}; - -// parser -typedef struct Prs_Man_t_ Prs_Man_t; -struct Prs_Man_t_ -{ - // input data - char * pName; // file name - char * pBuffer; // file contents - char * pLimit; // end of file - char * pCur; // current position - Abc_Nam_t * pStrs; // string manager - Abc_Nam_t * pFuns; // cover manager - Hash_IntMan_t * vHash; // variable ranges - Prs_Ntk_t * pNtk; // current network - Vec_Ptr_t * vNtks; // input networks - // temporary data - Vec_Str_t vCover; // one SOP cover - Vec_Int_t vTemp; // array of tokens - Vec_Int_t vTemp2; // array of tokens - Vec_Int_t vTemp3; // array of tokens - Vec_Int_t vTemp4; // array of tokens - // statistics - Vec_Int_t vKnown; - Vec_Int_t vFailed; - Vec_Int_t vSucceeded; - // error handling - int nOpens; // open port counter - int fUsingTemp2; // vTemp2 is in use - int FuncNameId; // temp value - int FuncRangeId; // temp value - char ErrorStr[1000]; // error -}; - -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)->pFuns; } - -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); } -static inline int Prs_NtkPiNum( Prs_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); } -static inline int Prs_NtkPoNum( Prs_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); } -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->pFuns, h); } -static inline char * Prs_NtkConst( Prs_Ntk_t * p, int h ) { return Abc_NamStr(p->pFuns, 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); } -static inline int Ptr_NtkRangeSize( Prs_Ntk_t * p, int h ) { int l = Hash_IntObjData0(p->vHash, h), r = Hash_IntObjData1(p->vHash, h); return 1 + (l > r ? l-r : r-l); } - -static inline int Prs_SliceName( Prs_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h); } -static inline int Prs_SliceRange( Prs_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h+1); } - -static inline int Prs_CatSize( Prs_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vConcats, h); } -static inline int * Prs_CatArray( Prs_Ntk_t * p, int h ) { return Vec_IntEntryP(&p->vConcats, h+1); } -static inline Vec_Int_t * Prs_CatSignals( Prs_Ntk_t * p, int h ) { static Vec_Int_t V; V.nSize = V.nCap = Prs_CatSize(p, h); V.pArray = Prs_CatArray(p, h); return &V; } - -static inline int Prs_BoxHand( Prs_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vObjs, i); } -static inline int Prs_BoxSize( Prs_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Prs_BoxHand(p, i))-2; } -static inline int Prs_BoxIONum( Prs_Ntk_t * p, int i ) { return Prs_BoxSize(p, i) / 2; } -static inline int Prs_BoxNtk( Prs_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Prs_BoxHand(p, i)+1); } -static inline void Prs_BoxSetNtk( Prs_Ntk_t * p, int i, int m ) { Vec_IntWriteEntry(&p->vBoxes, Prs_BoxHand(p, i)+1, m); } -static inline int Prs_BoxName( Prs_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Prs_BoxHand(p, i)+2); } -static inline int Prs_BoxIsNode( Prs_Ntk_t * p, int i ) { return!Vec_IntEntry(&p->vBoxes, Prs_BoxHand(p, i)+3); } // no formal names -static inline int * Prs_BoxArray( Prs_Ntk_t * p, int i ) { return Vec_IntEntryP(&p->vBoxes, Prs_BoxHand(p, i)+3); } -static inline Vec_Int_t * Prs_BoxSignals( Prs_Ntk_t * p, int i ) { static Vec_Int_t V; V.nSize = V.nCap = Prs_BoxSize(p, i); V.pArray = Prs_BoxArray(p, i); return &V; } - -#define Prs_ManForEachNameVec( vVec, p, pName, i ) \ - for ( i = 0; (i < Vec_IntSize(vVec)) && ((pName) = Abc_NamStr(p->pStrs, Vec_IntEntry(vVec,i))); i++ ) - -#define Prs_NtkForEachPio( p, NameId, i ) \ - for ( i = 0; i < Prs_NtkPioNum(p) && ((NameId) = Vec_IntEntry(&p->vInouts, i)); i++ ) -#define Prs_NtkForEachPi( p, NameId, i ) \ - for ( i = 0; i < Prs_NtkPiNum(p) && ((NameId) = Vec_IntEntry(&p->vInputs, i)); i++ ) -#define Prs_NtkForEachPo( p, NameId, i ) \ - for ( i = 0; i < Prs_NtkPoNum(p) && ((NameId) = Vec_IntEntry(&p->vOutputs, i)); i++ ) -#define Prs_NtkForEachBox( p, vVec, i ) \ - for ( i = 0; i < Prs_NtkBoxNum(p) && ((vVec) = Prs_BoxSignals(p, i)); i++ ) - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -// create error message -static inline int Prs_ManErrorSet( Prs_Man_t * p, char * pError, int Value ) -{ - assert( !p->ErrorStr[0] ); - sprintf( p->ErrorStr, "%s", pError ); - return Value; -} -// clear error message -static inline void Prs_ManErrorClear( Prs_Man_t * p ) -{ - p->ErrorStr[0] = '\0'; -} -// print error message -static inline int Prs_ManErrorPrint( Prs_Man_t * p ) -{ - char * pThis; int iLine = 0; - if ( !p->ErrorStr[0] ) return 1; - for ( pThis = p->pBuffer; pThis < p->pCur; pThis++ ) - iLine += (int)(*pThis == '\n'); - printf( "Line %d: %s\n", iLine, p->ErrorStr ); - return 0; -} - -// parsing network -static inline void Prs_ManInitializeNtk( Prs_Man_t * p, int iName, int fSlices ) -{ - assert( p->pNtk == NULL ); - p->pNtk = ABC_CALLOC( Prs_Ntk_t, 1 ); - p->pNtk->iModuleName = iName; - p->pNtk->fSlices = fSlices; - p->pNtk->pStrs = Abc_NamRef( p->pStrs ); - p->pNtk->pFuns = Abc_NamRef( p->pFuns ); - p->pNtk->vHash = Hash_IntManRef( p->vHash ); - Vec_PtrPush( p->vNtks, p->pNtk ); -} -static inline void Prs_ManFinalizeNtk( Prs_Man_t * p ) -{ - assert( p->pNtk != NULL ); - p->pNtk = NULL; -} - -static inline int Prs_ManNewStrId( Prs_Man_t * p, const char * format, ... ) -{ - Abc_Nam_t * pStrs = p->pStrs; - Vec_Str_t * vBuf = Abc_NamBuffer( pStrs ); - int nAdded, nSize = 1000; - va_list args; va_start( args, format ); - Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nSize ); - nAdded = vsnprintf( Vec_StrLimit(vBuf), nSize, format, args ); - if ( nAdded > nSize ) - { - Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nAdded + nSize ); - nSize = vsnprintf( Vec_StrLimit(vBuf), nAdded, format, args ); - assert( nSize == nAdded ); - } - va_end( args ); - return Abc_NamStrFindOrAddLim( pStrs, Vec_StrLimit(vBuf), Vec_StrLimit(vBuf) + nAdded, NULL ); -} - -// parsing slice/concatentation/box -static inline int Prs_NtkAddSlice( Prs_Ntk_t * p, int Name, int Range ) -{ - int Value = Vec_IntSize(&p->vSlices); - Vec_IntPushTwo( &p->vSlices, Name, Range ); - return Value; -} -static inline int Prs_NtkAddConcat( Prs_Ntk_t * p, Vec_Int_t * vTemp ) -{ - int Value; - if ( !(Vec_IntSize(&p->vConcats) & 1) ) - Vec_IntPush(&p->vConcats, -1); - Value = Vec_IntSize(&p->vConcats); - assert( Value & 1 ); - Vec_IntPush( &p->vConcats, Vec_IntSize(vTemp) ); - Vec_IntAppend( &p->vConcats, vTemp ); - return Value; -} -static inline void Prs_NtkAddBox( Prs_Ntk_t * p, int ModName, int InstName, Vec_Int_t * vTemp ) -{ - int Value; - assert( Vec_IntSize(vTemp) % 2 == 0 ); - if ( !(Vec_IntSize(&p->vBoxes) & 1) ) - Vec_IntPush(&p->vBoxes, -1); - Value = Vec_IntSize(&p->vBoxes); - assert( Value & 1 ); - Vec_IntPush( &p->vObjs, Value ); - // create entry - Vec_IntPush( &p->vBoxes, Vec_IntSize(vTemp)+2 ); - Vec_IntPush( &p->vBoxes, ModName ); - Vec_IntPush( &p->vBoxes, InstName ); - Vec_IntAppend( &p->vBoxes, vTemp ); -} -static inline char * Prs_ManLoadFile( char * pFileName, char ** ppLimit ) -{ - char * pBuffer; - int nFileSize, RetValue; - FILE * pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - printf( "Cannot open input file.\n" ); - return NULL; - } - // get the file size, in bytes - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - // move the file current reading position to the beginning - rewind( pFile ); - // load the contents of the file into memory - pBuffer = ABC_ALLOC( char, nFileSize + 16 ); - pBuffer[0] = '\n'; - RetValue = fread( pBuffer+1, nFileSize, 1, pFile ); - fclose( pFile ); - // terminate the string with '\0' - pBuffer[nFileSize + 1] = '\n'; - pBuffer[nFileSize + 2] = '\0'; - *ppLimit = pBuffer + nFileSize + 3; - return pBuffer; -} -static inline Prs_Man_t * Prs_ManAlloc( char * pFileName ) -{ - Prs_Man_t * p; - p = ABC_CALLOC( Prs_Man_t, 1 ); - if ( pFileName ) - { - char * pBuffer, * pLimit; - pBuffer = Prs_ManLoadFile( pFileName, &pLimit ); - if ( pBuffer == NULL ) - return NULL; - p->pName = pFileName; - p->pBuffer = pBuffer; - p->pLimit = pLimit; - p->pCur = pBuffer; - } - p->pStrs = Abc_NamStart( 1000, 24 ); - p->pFuns = Abc_NamStart( 100, 24 ); - p->vHash = Hash_IntManStart( 1000 ); - p->vNtks = Vec_PtrAlloc( 100 ); - return p; -} - -static inline void Prs_NtkFree( Prs_Ntk_t * p ) -{ - if ( p->pStrs ) Abc_NamDeref( p->pStrs ); - if ( p->pFuns ) Abc_NamDeref( p->pFuns ); - if ( p->vHash ) Hash_IntManDeref( p->vHash ); - Vec_IntErase( &p->vOrder ); - Vec_IntErase( &p->vInouts ); - Vec_IntErase( &p->vInputs ); - Vec_IntErase( &p->vOutputs ); - Vec_IntErase( &p->vWires ); - Vec_IntErase( &p->vInoutsR ); - Vec_IntErase( &p->vInputsR ); - Vec_IntErase( &p->vOutputsR ); - Vec_IntErase( &p->vWiresR ); - Vec_IntErase( &p->vSlices ); - Vec_IntErase( &p->vConcats ); - Vec_IntErase( &p->vBoxes ); - Vec_IntErase( &p->vObjs ); - ABC_FREE( p ); -} - -static inline void Prs_ManVecFree( Vec_Ptr_t * vPrs ) -{ - Prs_Ntk_t * pNtk; int i; - Vec_PtrForEachEntry( Prs_Ntk_t *, vPrs, pNtk, i ) - Prs_NtkFree( pNtk ); - Vec_PtrFree( vPrs ); -} - -static inline void Prs_ManFree( Prs_Man_t * p ) -{ - if ( p->pStrs ) Abc_NamDeref( p->pStrs ); - if ( p->pFuns ) Abc_NamDeref( p->pFuns ); - if ( p->vHash ) Hash_IntManDeref( p->vHash ); - if ( p->vNtks ) Prs_ManVecFree( p->vNtks ); - // temporary - Vec_StrErase( &p->vCover ); - Vec_IntErase( &p->vTemp ); - Vec_IntErase( &p->vTemp2 ); - Vec_IntErase( &p->vTemp3 ); - Vec_IntErase( &p->vTemp4 ); - Vec_IntErase( &p->vKnown ); - Vec_IntErase( &p->vFailed ); - Vec_IntErase( &p->vSucceeded ); - ABC_FREE( p->pBuffer ); - ABC_FREE( p ); -} - -static inline int Prs_NtkMemory( Prs_Ntk_t * p ) -{ - int nMem = sizeof(Prs_Ntk_t); - nMem += Vec_IntMemory( &p->vOrder ); - nMem += Vec_IntMemory( &p->vInouts ); - nMem += Vec_IntMemory( &p->vInputs ); - nMem += Vec_IntMemory( &p->vOutputs ); - nMem += Vec_IntMemory( &p->vWires ); - nMem += Vec_IntMemory( &p->vInoutsR ); - nMem += Vec_IntMemory( &p->vInputsR ); - nMem += Vec_IntMemory( &p->vOutputsR ); - nMem += Vec_IntMemory( &p->vWiresR ); - nMem += Vec_IntMemory( &p->vSlices ); - nMem += Vec_IntMemory( &p->vBoxes ); - nMem += Vec_IntMemory( &p->vConcats ); - return nMem; -} -static inline int Prs_ManMemory( Vec_Ptr_t * vPrs ) -{ - Prs_Ntk_t * pNtk; int i; - int nMem = Vec_PtrMemory(vPrs); - Vec_PtrForEachEntry( Prs_Ntk_t *, vPrs, pNtk, i ) - nMem += Prs_NtkMemory( pNtk ); - nMem += Abc_NamMemUsed(Prs_ManNameMan(vPrs)); - return nMem; -} - - -/**Function************************************************************* - - Synopsis [Other APIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Cba_ObjType_t Ptr_SopToType( char * pSop ) -{ - if ( !strcmp(pSop, " 0\n") ) return CBA_BOX_CF; - if ( !strcmp(pSop, " 1\n") ) return CBA_BOX_CT; - if ( !strcmp(pSop, "1 1\n") ) return CBA_BOX_BUF; - if ( !strcmp(pSop, "0 1\n") ) return CBA_BOX_INV; - if ( !strcmp(pSop, "11 1\n") ) return CBA_BOX_AND; - if ( !strcmp(pSop, "00 1\n") ) return CBA_BOX_NOR; - if ( !strcmp(pSop, "00 0\n") ) return CBA_BOX_OR; - if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return CBA_BOX_OR; - if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return CBA_BOX_OR; - if ( !strcmp(pSop, "01 1\n10 1\n") ) return CBA_BOX_XOR; - if ( !strcmp(pSop, "10 1\n01 1\n") ) return CBA_BOX_XOR; - 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; -} -static inline char * Ptr_SopToTypeName( char * pSop ) -{ - if ( !strcmp(pSop, " 0\n") ) return "CBA_BOX_C0"; - if ( !strcmp(pSop, " 1\n") ) return "CBA_BOX_C1"; - if ( !strcmp(pSop, "1 1\n") ) return "CBA_BOX_BUF"; - if ( !strcmp(pSop, "0 1\n") ) return "CBA_BOX_INV"; - if ( !strcmp(pSop, "11 1\n") ) return "CBA_BOX_AND"; - if ( !strcmp(pSop, "00 1\n") ) return "CBA_BOX_NOR"; - if ( !strcmp(pSop, "00 0\n") ) return "CBA_BOX_OR"; - if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return "CBA_BOX_OR"; - if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return "CBA_BOX_OR"; - if ( !strcmp(pSop, "01 1\n10 1\n") ) return "CBA_BOX_XOR"; - if ( !strcmp(pSop, "10 1\n01 1\n") ) return "CBA_BOX_XOR"; - 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; -} -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"; - if ( Type == CBA_BOX_NAND ) return "nand"; - if ( Type == CBA_BOX_OR ) return "or"; - if ( Type == CBA_BOX_NOR ) return "nor"; - if ( Type == CBA_BOX_XOR ) return "xor"; - if ( Type == CBA_BOX_XNOR ) return "xnor"; - 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"; - if ( Type == CBA_BOX_TRI) return "bufifl"; - assert( 0 ); - return "???"; -} -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"; - if ( Type == CBA_BOX_NAND ) return "11 0\n"; - if ( Type == CBA_BOX_OR ) return "00 0\n"; - if ( Type == CBA_BOX_NOR ) return "00 1\n"; - 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 ); - return "???"; -} - - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/*=== cbaReadVer.c ========================================================*/ -extern void Prs_NtkAddVerilogDirectives( Prs_Man_t * p ); - - -ABC_NAMESPACE_HEADER_END - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/base/cba/cbaReadBlif.c b/src/base/cba/cbaReadBlif.c deleted file mode 100644 index fff984138..000000000 --- a/src/base/cba/cbaReadBlif.c +++ /dev/null @@ -1,646 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaReadBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [BLIF parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaReadBlif.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" -#include "cbaPrs.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// BLIF keywords -typedef enum { - PRS_BLIF_NONE = 0, // 0: unused - PRS_BLIF_MODEL, // 1: .model - PRS_BLIF_INOUTS, // 2: .inouts - PRS_BLIF_INPUTS, // 3: .inputs - PRS_BLIF_OUTPUTS, // 4: .outputs - PRS_BLIF_NAMES, // 5: .names - PRS_BLIF_SUBCKT, // 6: .subckt - PRS_BLIF_GATE, // 7: .gate - PRS_BLIF_LATCH, // 8: .latch - PRS_BLIF_SHORT, // 9: .short - PRS_BLIF_END, // 10: .end - PRS_BLIF_UNKNOWN // 11: unknown -} Cba_BlifType_t; - -static const char * s_BlifTypes[PRS_BLIF_UNKNOWN+1] = { - NULL, // 0: unused - ".model", // 1: .model - ".inouts", // 2: .inputs - ".inputs", // 3: .inputs - ".outputs", // 4: .outputs - ".names", // 5: .names - ".subckt", // 6: .subckt - ".gate", // 7: .gate - ".latch", // 8: .latch - ".short", // 9: .short - ".end", // 10: .end - NULL // 11: unknown -}; - -static inline void Prs_NtkAddBlifDirectives( Prs_Man_t * p ) -{ - int i; - for ( i = 1; s_BlifTypes[i]; i++ ) - Abc_NamStrFindOrAdd( p->pStrs, (char *)s_BlifTypes[i], NULL ); - assert( Abc_NamObjNumMax(p->pStrs) == i ); -} - - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Reading characters.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_CharIsSpace( char c ) { return c == ' ' || c == '\t' || c == '\r'; } -static inline int Prs_CharIsStop( char c ) { return c == '#' || c == '\\' || c == '\n' || c == '='; } -static inline int Prs_CharIsLit( char c ) { return c == '0' || c == '1' || c == '-'; } - -static inline int Prs_ManIsSpace( Prs_Man_t * p ) { return Prs_CharIsSpace(*p->pCur); } -static inline int Prs_ManIsStop( Prs_Man_t * p ) { return Prs_CharIsStop(*p->pCur); } -static inline int Prs_ManIsLit( Prs_Man_t * p ) { return Prs_CharIsLit(*p->pCur); } - -static inline int Prs_ManIsChar( Prs_Man_t * p, char c ) { return *p->pCur == c; } -static inline int Prs_ManIsChar2( Prs_Man_t * p, char c ) { return *p->pCur++ == c; } - -static inline void Prs_ManSkip( Prs_Man_t * p ) { p->pCur++; } -static inline char Prs_ManSkip2( Prs_Man_t * p ) { return *p->pCur++; } - - -/**Function************************************************************* - - Synopsis [Reading names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Prs_ManSkipToChar( Prs_Man_t * p, char c ) -{ - while ( !Prs_ManIsChar(p, c) ) - Prs_ManSkip(p); -} -static inline void Prs_ManSkipSpaces( Prs_Man_t * p ) -{ - while ( 1 ) - { - while ( Prs_ManIsSpace(p) ) - Prs_ManSkip(p); - if ( Prs_ManIsChar(p, '\\') ) - { - Prs_ManSkipToChar( p, '\n' ); - Prs_ManSkip(p); - continue; - } - if ( Prs_ManIsChar(p, '#') ) - Prs_ManSkipToChar( p, '\n' ); - break; - } - assert( !Prs_ManIsSpace(p) ); -} -static inline int Prs_ManReadName( Prs_Man_t * p ) -{ - char * pStart; - Prs_ManSkipSpaces( p ); - if ( Prs_ManIsChar(p, '\n') ) - return 0; - pStart = p->pCur; - while ( !Prs_ManIsSpace(p) && !Prs_ManIsStop(p) ) - Prs_ManSkip(p); - if ( pStart == p->pCur ) - return 0; - return Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur, NULL ); -} -static inline int Prs_ManReadList( Prs_Man_t * p, Vec_Int_t * vOrder, int Type ) -{ - int iToken; - Vec_IntClear( &p->vTemp ); - while ( (iToken = Prs_ManReadName(p)) ) - { - Vec_IntPush( &p->vTemp, iToken ); - Vec_IntPush( vOrder, Abc_Var2Lit2(iToken, Type) ); - } - if ( Vec_IntSize(&p->vTemp) == 0 ) return Prs_ManErrorSet(p, "Signal list is empty.", 1); - return 0; -} -static inline int Prs_ManReadList2( Prs_Man_t * p ) -{ - int iToken; - Vec_IntClear( &p->vTemp ); - while ( (iToken = Prs_ManReadName(p)) ) - Vec_IntPushTwo( &p->vTemp, 0, iToken ); - if ( Vec_IntSize(&p->vTemp) == 0 ) return Prs_ManErrorSet(p, "Signal list is empty.", 1); - return 0; -} -static inline int Prs_ManReadList3( Prs_Man_t * p ) -{ - Vec_IntClear( &p->vTemp ); - while ( !Prs_ManIsChar(p, '\n') ) - { - int iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read formal name.", 1); - Vec_IntPush( &p->vTemp, iToken ); - Prs_ManSkipSpaces( p ); - if ( !Prs_ManIsChar2(p, '=') ) return Prs_ManErrorSet(p, "Cannot find symbol \"=\".", 1); - iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read actual name.", 1); - Vec_IntPush( &p->vTemp, iToken ); - Prs_ManSkipSpaces( p ); - } - if ( Vec_IntSize(&p->vTemp) == 0 ) return Prs_ManErrorSet(p, "Cannot read a list of formal/actual names.", 1); - if ( Vec_IntSize(&p->vTemp) % 2 ) return Prs_ManErrorSet(p, "The number of formal/actual names is not even.", 1); - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_ManReadCube( Prs_Man_t * p ) -{ - assert( Prs_ManIsLit(p) ); - while ( Prs_ManIsLit(p) ) - Vec_StrPush( &p->vCover, Prs_ManSkip2(p) ); - Prs_ManSkipSpaces( p ); - if ( Prs_ManIsChar(p, '\n') ) - { - if ( Vec_StrSize(&p->vCover) != 1 ) return Prs_ManErrorSet(p, "Cannot read cube.", 1); - // fix single literal cube by adding space - Vec_StrPush( &p->vCover, Vec_StrEntry(&p->vCover,0) ); - Vec_StrWriteEntry( &p->vCover, 0, ' ' ); - Vec_StrPush( &p->vCover, '\n' ); - return 0; - } - if ( !Prs_ManIsLit(p) ) return Prs_ManErrorSet(p, "Cannot read output literal.", 1); - Vec_StrPush( &p->vCover, ' ' ); - Vec_StrPush( &p->vCover, Prs_ManSkip2(p) ); - Vec_StrPush( &p->vCover, '\n' ); - Prs_ManSkipSpaces( p ); - if ( !Prs_ManIsChar(p, '\n') ) return Prs_ManErrorSet(p, "Cannot read end of cube.", 1); - return 0; -} -static inline void Prs_ManSaveCover( Prs_Man_t * p ) -{ - int iToken; - if ( Vec_StrSize(&p->vCover) == 0 ) - p->pNtk->fHasC0s = 1; - else if ( Vec_StrSize(&p->vCover) == 2 ) - { - if ( Vec_StrEntryLast(&p->vCover) == '0' ) - p->pNtk->fHasC0s = 1; - else if ( Vec_StrEntryLast(&p->vCover) == '1' ) - p->pNtk->fHasC1s = 1; - else assert( 0 ); - } - assert( Vec_StrSize(&p->vCover) > 0 ); - Vec_StrPush( &p->vCover, '\0' ); -// iToken = Ptr_SopToType( Vec_StrArray(&p->vCover) ); - iToken = Abc_NamStrFindOrAdd( p->pFuns, 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 - Prs_BoxSetNtk( p->pNtk, Prs_NtkBoxNum(p->pNtk)-1, iToken ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_ManReadInouts( Prs_Man_t * p ) -{ - if ( Prs_ManReadList(p, &p->pNtk->vOrder, 3) ) return 1; - Vec_IntAppend( &p->pNtk->vInouts, &p->vTemp ); - return 0; -} -static inline int Prs_ManReadInputs( Prs_Man_t * p ) -{ - if ( Prs_ManReadList(p, &p->pNtk->vOrder, 1) ) return 1; - Vec_IntAppend( &p->pNtk->vInputs, &p->vTemp ); - return 0; -} -static inline int Prs_ManReadOutputs( Prs_Man_t * p ) -{ - if ( Prs_ManReadList(p, &p->pNtk->vOrder, 2) ) return 1; - Vec_IntAppend( &p->pNtk->vOutputs, &p->vTemp ); - return 0; -} -static inline int Prs_ManReadNode( Prs_Man_t * p ) -{ - if ( Prs_ManReadList2(p) ) return 1; - // save results - Prs_NtkAddBox( p->pNtk, 1, 0, &p->vTemp ); // default const 0 function - return 0; -} -static inline int Prs_ManReadBox( Prs_Man_t * p, int fGate ) -{ - int iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read model name.", 1); - if ( Prs_ManReadList3(p) ) return 1; - // save results - Prs_NtkAddBox( p->pNtk, iToken, 0, &p->vTemp ); - if ( fGate ) p->pNtk->fMapped = 1; - return 0; -} -static inline int Prs_ManReadLatch( Prs_Man_t * p ) -{ - int iToken = Prs_ManReadName(p); - Vec_IntClear( &p->vTemp ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read latch input.", 1); - Vec_IntWriteEntry( &p->vTemp, 1, iToken ); - iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read latch output.", 1); - Vec_IntWriteEntry( &p->vTemp, 0, iToken ); - Prs_ManSkipSpaces( p ); - if ( Prs_ManIsChar(p, '0') ) - iToken = 0; - else if ( Prs_ManIsChar(p, '1') ) - iToken = 1; - else - iToken = 2; - Prs_ManSkipToChar( p, '\n' ); - // save results - Prs_NtkAddBox( p->pNtk, -1, iToken, &p->vTemp ); // -1 stands for latch - return 0; -} -static inline int Prs_ManReadShort( Prs_Man_t * p ) -{ - int iToken = Prs_ManReadName(p); - Vec_IntClear( &p->vTemp ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read .short input.", 1); - Vec_IntWriteEntry( &p->vTemp, 1, iToken ); - iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read .short output.", 1); - Vec_IntWriteEntry( &p->vTemp, 0, iToken ); - Prs_ManSkipSpaces( p ); - if ( !Prs_ManIsChar(p, '\n') ) return Prs_ManErrorSet(p, "Trailing symbols on .short line.", 1); - // save results - iToken = Abc_NamStrFindOrAdd( p->pStrs, "1 1\n", NULL ); - Prs_NtkAddBox( p->pNtk, iToken, 0, &p->vTemp ); - return 0; -} -static inline int Prs_ManReadModel( Prs_Man_t * p ) -{ - int iToken; - if ( p->pNtk != NULL ) return Prs_ManErrorSet(p, "Parsing previous model is unfinished.", 1); - iToken = Prs_ManReadName(p); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read model name.", 1); - Prs_ManInitializeNtk( p, iToken, 0 ); - Prs_ManSkipSpaces( p ); - if ( !Prs_ManIsChar(p, '\n') ) return Prs_ManErrorSet(p, "Trailing symbols on .model line.", 1); - return 0; -} -static inline int Prs_ManReadEnd( Prs_Man_t * p ) -{ - if ( p->pNtk == 0 ) return Prs_ManErrorSet(p, "Directive .end without .model.", 1); - //printf( "Saving model \"%s\".\n", Abc_NamStr(p->pStrs, p->iModuleName) ); - Prs_ManFinalizeNtk( p ); - Prs_ManSkipSpaces( p ); - if ( !Prs_ManIsChar(p, '\n') ) return Prs_ManErrorSet(p, "Trailing symbols on .end line.", 1); - return 0; -} - -static inline int Prs_ManReadDirective( Prs_Man_t * p ) -{ - int iToken; - if ( !Prs_ManIsChar(p, '.') ) - return Prs_ManReadCube( p ); - if ( Vec_StrSize(&p->vCover) > 0 ) // SOP was specified for the previous node - Prs_ManSaveCover( p ); - iToken = Prs_ManReadName( p ); - if ( iToken == PRS_BLIF_MODEL ) - return Prs_ManReadModel( p ); - if ( iToken == PRS_BLIF_INOUTS ) - return Prs_ManReadInouts( p ); - if ( iToken == PRS_BLIF_INPUTS ) - return Prs_ManReadInputs( p ); - if ( iToken == PRS_BLIF_OUTPUTS ) - return Prs_ManReadOutputs( p ); - if ( iToken == PRS_BLIF_NAMES ) - return Prs_ManReadNode( p ); - if ( iToken == PRS_BLIF_SUBCKT ) - return Prs_ManReadBox( p, 0 ); - if ( iToken == PRS_BLIF_GATE ) - return Prs_ManReadBox( p, 1 ); - if ( iToken == PRS_BLIF_LATCH ) - return Prs_ManReadLatch( p ); - if ( iToken == PRS_BLIF_SHORT ) - return Prs_ManReadShort( p ); - if ( iToken == PRS_BLIF_END ) - return Prs_ManReadEnd( p ); - printf( "Cannot read directive \"%s\".\n", Abc_NamStr(p->pStrs, iToken) ); - return 1; -} -static inline int Prs_ManReadLines( Prs_Man_t * p ) -{ - while ( p->pCur[1] != '\0' ) - { - assert( Prs_ManIsChar(p, '\n') ); - Prs_ManSkip(p); - Prs_ManSkipSpaces( p ); - if ( Prs_ManIsChar(p, '\n') ) - continue; - if ( Prs_ManReadDirective(p) ) - return 1; - } - return 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Prs_ManReadBlif( char * pFileName ) -{ - Vec_Ptr_t * vPrs = NULL; - Prs_Man_t * p = Prs_ManAlloc( pFileName ); - if ( p == NULL ) - return NULL; - Abc_NamStrFindOrAdd( p->pFuns, " 0\n", NULL ); - Abc_NamStrFindOrAdd( p->pFuns, " 1\n", NULL ); - Prs_NtkAddBlifDirectives( p ); - Prs_ManReadLines( p ); - if ( Prs_ManErrorPrint(p) ) - ABC_SWAP( Vec_Ptr_t *, vPrs, p->vNtks ); - Prs_ManFree( p ); - return vPrs; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Prs_ManReadBlifTest( char * pFileName ) -{ - abctime clk = Abc_Clock(); - Vec_Ptr_t * vPrs = Prs_ManReadBlif( pFileName ); - 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( Extra_FileNameGenericAppend(pFileName, "_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 * pFuns = Abc_NamRef(pPrsRoot->pFuns); - Abc_Nam_t * pMods = Abc_NamStart( 100, 24 ); - Cba_Man_t * p = Cba_ManAlloc( pFileName, Vec_PtrSize(vDes), pStrs, pFuns, pMods, NULL ); - // 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) ); - 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 /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaReadVer.c b/src/base/cba/cbaReadVer.c deleted file mode 100644 index 256119085..000000000 --- a/src/base/cba/cbaReadVer.c +++ /dev/null @@ -1,2182 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaReadVer.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [BLIF writer.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaReadVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" -#include "cbaPrs.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -static const char * s_VerTypes[PRS_VER_UNKNOWN+1] = { - NULL, // 0: unused - "input", // 1: input - "output", // 2: output - "inout", // 3: inout - "wire", // 4: wire - "reg", // 5: reg - "module", // 6: module - "assign", // 7: assign - "always", // 8: always - "function", // 9: function - "defparam", // 10: defparam - "begin", // 11: begin - "end", // 12: end - "case", // 13: case - "endcase", // 14: endcase - "signed", // 15: signed - "endmodule", // 16: endmodule - NULL // 17: unknown -}; - -void Prs_NtkAddVerilogDirectives( Prs_Man_t * p ) -{ - int i; - for ( i = 1; s_VerTypes[i]; i++ ) - Abc_NamStrFindOrAdd( p->pStrs, (char *)s_VerTypes[i], NULL ); - assert( Abc_NamObjNumMax(p->pStrs) == i ); -} - - -// character recognition -static inline int Prs_CharIsSpace( char c ) { return (c == ' ' || c == '\t' || c == '\r' || c == '\n'); } -static inline int Prs_CharIsDigit( char c ) { return (c >= '0' && c <= '9'); } -static inline int Prs_CharIsDigitB( char c ) { return (c == '0' || c == '1' || c == 'x' || c == 'z'); } -static inline int Prs_CharIsDigitH( char c ) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); } -static inline int Prs_CharIsChar( char c ) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } -static inline int Prs_CharIsSymb1( char c ) { return Prs_CharIsChar(c) || c == '_'; } -static inline int Prs_CharIsSymb2( char c ) { return Prs_CharIsSymb1(c) || Prs_CharIsDigit(c) || c == '$'; } - -static inline int Prs_ManIsChar( Prs_Man_t * p, char c ) { return p->pCur[0] == c; } -static inline int Prs_ManIsChar1( Prs_Man_t * p, char c ) { return p->pCur[1] == c; } -static inline int Prs_ManIsDigit( Prs_Man_t * p ) { return Prs_CharIsDigit(*p->pCur); } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - -// predefined primitives -typedef struct Prs_VerPrim_t_ Prs_VerPrim_t; -struct Prs_VerPrim_t_ -{ - int Type; - char * pName; -}; -static const Prs_VerPrim_t s_VerilogPrims[16] = -{ - {CBA_BOX_BUF, "buf" }, - {CBA_BOX_INV, "not" }, - {CBA_BOX_AND, "and" }, - {CBA_BOX_NAND, "nand" }, - {CBA_BOX_OR, "or" }, - {CBA_BOX_NOR, "nor" }, - {CBA_BOX_XOR, "xor" }, - {CBA_BOX_XNOR, "xnor" }, - {CBA_BOX_TRI, "bufif1"}, - {0} -}; - -// predefined operator names -static const char * s_VerNames[100] = -{ - NULL, - "VERIFIC_", - "add_", - "mult_", - "div_", - "mod_", - "rem_", - "shift_left_", - "shift_right_", - "rotate_left_", - "rotate_right_", - "reduce_and_", - "reduce_or_", - "reduce_xor_", - "reduce_nand_", - "reduce_nor_", - "reduce_xnor_", - "LessThan_", - "Mux_", - "Select_", - "Decoder_", - "EnabledDecoder_", - "PrioSelect_", - "DualPortRam_", - "ReadPort_", - "WritePort_", - "ClockedWritePort_", - "lut", - "and_", - "or_", - "xor_", - "nand_", - "nor_", - "xnor_", - "buf_", - "inv_", - "tri_", - "sub_", - "unary_minus_", - "equal_", - "not_equal_", - "mux_", - "wide_mux_", - "wide_select_", - "wide_dff_", - "wide_dlatch_", - "wide_dffrs_", - "wide_dlatchrs_", - "wide_prio_select_", - "pow_", - "PrioEncoder_", - "abs_", - "CPL_NMACROFF", - "CPL_MACROFF", - "CPL_FF", - NULL -}; - -typedef struct Prs_VerInfo_t_ Prs_VerInfo_t; -struct Prs_VerInfo_t_ -{ - int Type; - int nInputs; - char * pTypeName; - char * pSigNames[6]; -}; -static const Prs_VerInfo_t s_VerInfo[100] = -{ - {-1, 0, NULL, /* "PRIM_NONE" */ {NULL}}, - {CBA_BOX_CT, 0, "VERIFIC_PWR", /* "PRIM_PWR" */ {"o"}}, - {CBA_BOX_CF, 0, "VERIFIC_GND", /* "PRIM_GND" */ {"o"}}, - {CBA_BOX_CX, 0, "VERIFIC_X", /* "PRIM_X" */ {"o"}}, - {CBA_BOX_CZ, 0, "VERIFIC_Z", /* "PRIM_Z" */ {"o"}}, - {CBA_BOX_INV, 1, "VERIFIC_INV", /* "PRIM_INV" */ {"i","o"}}, - {CBA_BOX_BUF, 1, "VERIFIC_BUF", /* "PRIM_BUF" */ {"i","o"}}, - {CBA_BOX_AND, 1, "VERIFIC_AND", /* "PRIM_AND" */ {"a0","a1","o"}}, - {CBA_BOX_NAND, 2, "VERIFIC_NAND", /* "PRIM_NAND" */ {"a0","a1","o"}}, - {CBA_BOX_OR, 2, "VERIFIC_OR", /* "PRIM_OR" */ {"a0","a1","o"}}, - {CBA_BOX_NOR, 2, "VERIFIC_NOR", /* "PRIM_NOR" */ {"a0","a1","o"}}, - {CBA_BOX_XOR, 2, "VERIFIC_XOR", /* "PRIM_XOR" */ {"a0","a1","o"}}, - {CBA_BOX_XNOR, 2, "VERIFIC_XNOR", /* "PRIM_XNOR" */ {"a0","a1","o"}}, - {CBA_BOX_MUX, 3, "VERIFIC_MUX", /* "PRIM_MUX" */ {"c","a1","a0","o"}}, // changed order - {-1, 0, "VERIFIC_PULLUP", /* "PRIM_PULLUP" */ {"o"}}, - {-1, 0, "VERIFIC_PULLDOWN", /* "PRIM_PULLDOWN" */ {"o"}}, - {CBA_BOX_TRI, 3, "VERIFIC_TRI", /* "PRIM_TRI" */ {"i","c","o"}}, - {CBA_BOX_LATCHRS, 4, "VERIFIC_DLATCHRS", /* "PRIM_DLATCHRS" */ {"d","s","r","gate","q"}}, // changed order - {CBA_BOX_LATCH, 4, "VERIFIC_DLATCH", /* "PRIM_DLATCH" */ {"d","async_val","async_cond","gate","q"}}, // changed order - {CBA_BOX_DFFRS, 4, "VERIFIC_DFFRS", /* "PRIM_DFFRS" */ {"d","s","r","clk","q"}}, // changed order - {CBA_BOX_DFF, 4, "VERIFIC_DFF", /* "PRIM_DFF" */ {"d","async_val","async_cond","clk","q"}}, // changed order - {-1, 2, "VERIFIC_NMOS", /* "PRIM_NMOS" */ {"c","d","o"}}, - {-1, 2, "VERIFIC_PMOS", /* "PRIM_PMOS" */ {"c","d","o"}}, - {-1, 3, "VERIFIC_CMOS", /* "PRIM_CMOS" */ {"d","nc","pc","o"}}, - {-1, 2, "VERIFIC_TRAN", /* "PRIM_TRAN" */ {"inout1","inout2","control"}}, - {CBA_BOX_ADD, 3, "VERIFIC_FADD", /* "PRIM_FADD" */ {"cin","a","b","o","cout"}}, - {-1, 3, "VERIFIC_RCMOS", /* "PRIM_RCMOS" */ {"d","nc","pc","o"}}, - {-1, 2, "VERIFIC_RNMOS", /* "PRIM_RNMOS" */ {"c","d","o"}}, - {-1, 2, "VERIFIC_RPMOS", /* "PRIM_RPMOS" */ {"c","d","o"}}, - {-1, 2, "VERIFIC_RTRAN", /* "PRIM_RTRAN" */ {"inout1","inout2","control"}}, - {-1, 0, "VERIFIC_HDL_ASSERTION", /* "PRIM_HDL_ASSERTION" */ {"condition"}}, - {CBA_BOX_ADD, 3, "add_", /* "OPER_ADDER" */ {"cin","a","b","o","cout"}}, - {CBA_BOX_MUL, 2, "mult_", /* "OPER_MULTIPLIER" */ {"a","b","o"}}, - {CBA_BOX_DIV, 2, "div_", /* "OPER_DIVIDER" */ {"a","b","o"}}, - {CBA_BOX_MOD, 2, "mod_", /* "OPER_MODULO" */ {"a","b","o"}}, - {CBA_BOX_REM, 2, "rem_", /* "OPER_REMAINDER" */ {"a","b","o"}}, - {CBA_BOX_SHIL, 3, "shift_left_", /* "OPER_SHIFT_LEFT" */ {"cin","a","amount","o"}}, - {CBA_BOX_SHIR, 3, "shift_right_", /* "OPER_SHIFT_RIGHT" */ {"cin","a","amount","o"}}, - {CBA_BOX_ROTL, 2, "rotate_left_", /* "OPER_ROTATE_LEFT" */ {"a","amount","o"}}, - {CBA_BOX_ROTR, 2, "rotate_right_", /* "OPER_ROTATE_RIGHT" */ {"a","amount","o"}}, - {CBA_BOX_RAND, 1, "reduce_and_", /* "OPER_REDUCE_AND" */ {"a","o"}}, - {CBA_BOX_ROR, 1, "reduce_or_", /* "OPER_REDUCE_OR" */ {"a","o"}}, - {CBA_BOX_RXOR, 1, "reduce_xor_", /* "OPER_REDUCE_XOR" */ {"a","o"}}, - {CBA_BOX_RNAND, 1, "reduce_nand_", /* "OPER_REDUCE_NAND" */ {"a","o"}}, - {CBA_BOX_RNOR, 1, "reduce_nor_", /* "OPER_REDUCE_NOR" */ {"a","o"}}, - {CBA_BOX_RXNOR, 1, "reduce_xnor_", /* "OPER_REDUCE_XNOR" */ {"a","o"}}, - {CBA_BOX_LTHAN, 3, "LessThan_", /* "OPER_LESSTHAN" */ {"cin","a","b","o"}}, - {CBA_BOX_NMUX, 2, "Mux_", /* "OPER_NTO1MUX" */ {"sel","data","o"}}, - {CBA_BOX_SEL, 2, "Select_", /* "OPER_SELECTOR" */ {"sel","data","o"}}, - {CBA_BOX_DEC, 1, "Decoder_", /* "OPER_DECODER" */ {"a","o"}}, - {CBA_BOX_EDEC, 2, "EnabledDecoder_", /* "OPER_ENABLED_DECODER" */ {"en","i","o"}}, - {CBA_BOX_PSEL, 3, "PrioSelect_", /* "OPER_PRIO_SELECTOR" */ {"cin","sel","data","o"}}, - {CBA_BOX_RAM, 4, "DualPortRam_", /* "OPER_DUAL_PORT_RAM" */ {"write_enable","write_address","write_data","read_address","read_data"}}, - {CBA_BOX_RAMR, 3, "ReadPort_", /* "OPER_READ_PORT" */ {"read_enable", "read_address", "Ram", "read_data" }}, - {CBA_BOX_RAMW, 3, "WritePort_", /* "OPER_WRITE_PORT" */ {"write_enable","write_address","write_data", "Ram"}}, - {CBA_BOX_RAMWC, 4, "ClockedWritePort_", /* "OPER_CLOCKED_WRITE_PORT" */ {"clk","write_enable","write_address","write_data", "Ram"}}, - {CBA_BOX_LUT, 1, "lut", /* "OPER_LUT" */ {"i","o"}}, - {CBA_BOX_AND, 2, "and_", /* "OPER_WIDE_AND" */ {"a","b","o"}}, - {CBA_BOX_OR, 2, "or_", /* "OPER_WIDE_OR" */ {"a","b","o"}}, - {CBA_BOX_XOR, 2, "xor_", /* "OPER_WIDE_XOR" */ {"a","b","o"}}, - {CBA_BOX_NAND, 2, "nand_", /* "OPER_WIDE_NAND" */ {"a","b","o"}}, - {CBA_BOX_NOR, 2, "nor_", /* "OPER_WIDE_NOR" */ {"a","b","o"}}, - {CBA_BOX_XNOR, 2, "xnor_", /* "OPER_WIDE_XNOR" */ {"a","b","o"}}, - {CBA_BOX_BUF, 1, "buf_", /* "OPER_WIDE_BUF" */ {"i","o"}}, - {CBA_BOX_INV, 1, "inv_", /* "OPER_WIDE_INV" */ {"i","o"}}, - {CBA_BOX_TRI, 2, "tri_", /* "OPER_WIDE_TRI" */ {"i","c","o"}}, - {CBA_BOX_SUB, 2, "sub_", /* "OPER_MINUS" */ {"a","b","o"}}, - {CBA_BOX_MIN, 1, "unary_minus_", /* "OPER_UMINUS" */ {"i","o"}}, - {CBA_BOX_EQU, 2, "equal_", /* "OPER_EQUAL" */ {"a","b","o"}}, - {CBA_BOX_NEQU, 2, "not_equal_", /* "OPER_NEQUAL" */ {"a","b","o"}}, - {CBA_BOX_MUX, 3, "mux_", /* "OPER_WIDE_MUX" */ {"cond","d1","d0","o"}}, // changed order - {CBA_BOX_NMUX, 2, "wide_mux_", /* "OPER_WIDE_NTO1MUX" */ {"sel","data","o"}}, - {CBA_BOX_SEL, 2, "wide_select_", /* "OPER_WIDE_SELECTOR" */ {"sel","data","o"}}, - {CBA_BOX_DFF, 4, "wide_dff_", /* "OPER_WIDE_DFF" */ {"d","async_val","async_cond","clock","q"}}, - {CBA_BOX_DFFRS, 4, "wide_dffrs_", /* "OPER_WIDE_DFFRS" */ {"d","set","reset","clock","q"}}, - {CBA_BOX_LATCHRS, 4, "wide_dlatchrs_", /* "OPER_WIDE_DLATCHRS" */ {"d","set","reset","clock","q"}}, - {CBA_BOX_LATCH, 4, "wide_dlatch_", /* "OPER_WIDE_DLATCH" */ {"d","async_val","async_cond","clock","q"}}, - {CBA_BOX_PSEL, 3, "wide_prio_select_", /* "OPER_WIDE_PRIO_SELECTOR" */ {"sel","data","carry_in","o"}}, - {CBA_BOX_POW, 2, "pow_", /* "OPER_POW" */ {"a","b","o"}}, - {CBA_BOX_PENC, 1, "PrioEncoder_", /* "OPER_PRIO_ENCODER" */ {"sel","o"}}, - {CBA_BOX_ABS, 1, "abs_", /* "OPER_ABS" */ {"i","o"}}, - {CBA_BOX_DFFCPL, 4, "CPL_FF", /* "OPER_WIDE_DFF - 2" */ {"d","arstval","arst","clk","q","qbar"}}, - {-1, 0, NULL, /* "PRIM_END" */ {NULL}} -}; - - -// check if it is a Verilog predefined module -static inline int Prs_ManIsVerilogPrim( char * pName ) -{ - int i; - for ( i = 0; s_VerilogPrims[i].pName; i++ ) - if ( !strcmp(pName, s_VerilogPrims[i].pName) ) - return s_VerilogPrims[i].Type; - return 0; -} -// check if it is a known module -static inline int Prs_ManIsKnownModule( char * pName ) -{ - int i, Length; - for ( i = 1; s_VerNames[i]; i++ ) - { - Length = strlen(s_VerNames[i]); -// if ( !strncmp(pName, s_VerNames[i], Length) && (i == 1 || (pName[Length] >= '0' && pName[Length] <= '9')) ) - if ( !strncmp(pName, s_VerNames[i], Length) ) - return i; - } - return 0; -} -// check if it is a known module -static inline int Prs_ManFindType( char * pName, int * pInputs, int fOut, char *** ppNames ) -{ - int i, Length; - *pInputs = -1; - for ( i = 1; s_VerInfo[i].pTypeName; i++ ) - { - Length = strlen(s_VerInfo[i].pTypeName); - if ( !strncmp(pName, s_VerInfo[i].pTypeName, Length) ) - { - *pInputs = s_VerInfo[i].nInputs; - *ppNames = (char **)s_VerInfo[i].pSigNames + (fOut ? s_VerInfo[i].nInputs : 0); - return s_VerInfo[i].Type; - } - } - return CBA_OBJ_BOX; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - -// skips Verilog comments (returns 1 if some comments were skipped) -static inline int Prs_ManUtilSkipComments( Prs_Man_t * p ) -{ - if ( !Prs_ManIsChar(p, '/') ) - return 0; - if ( Prs_ManIsChar1(p, '/') ) - { - for ( p->pCur += 2; p->pCur < p->pLimit; p->pCur++ ) - if ( Prs_ManIsChar(p, '\n') ) - { p->pCur++; return 1; } - } - else if ( Prs_ManIsChar1(p, '*') ) - { - for ( p->pCur += 2; p->pCur < p->pLimit; p->pCur++ ) - if ( Prs_ManIsChar(p, '*') && Prs_ManIsChar1(p, '/') ) - { p->pCur++; p->pCur++; return 1; } - } - return 0; -} -static inline int Prs_ManUtilSkipName( Prs_Man_t * p ) -{ - if ( !Prs_ManIsChar(p, '\\') ) - return 0; - for ( p->pCur++; p->pCur < p->pLimit; p->pCur++ ) - if ( Prs_ManIsChar(p, ' ') ) - { p->pCur++; return 1; } - return 0; -} - -// skip any number of spaces and comments -static inline int Prs_ManUtilSkipSpaces( Prs_Man_t * p ) -{ - while ( p->pCur < p->pLimit ) - { - while ( Prs_CharIsSpace(*p->pCur) ) - p->pCur++; - if ( !*p->pCur ) - return Prs_ManErrorSet(p, "Unexpectedly reached end-of-file.", 1); - if ( !Prs_ManUtilSkipComments(p) ) - return 0; - } - return Prs_ManErrorSet(p, "Unexpectedly reached end-of-file.", 1); -} -// skip everything including comments until the given char -static inline int Prs_ManUtilSkipUntil( Prs_Man_t * p, char c ) -{ - while ( p->pCur < p->pLimit ) - { - if ( Prs_ManIsChar(p, c) ) - return 1; - if ( Prs_ManUtilSkipComments(p) ) - continue; - if ( Prs_ManUtilSkipName(p) ) - continue; - p->pCur++; - } - return 0; -} -// skip everything including comments until the given word -static inline int Prs_ManUtilSkipUntilWord( Prs_Man_t * p, char * pWord ) -{ - char * pPlace = strstr( p->pCur, pWord ); - if ( pPlace == NULL ) return 1; - p->pCur = pPlace + strlen(pWord); - return 0; -} -// detect two symbols on the same line -static inline int Prs_ManUtilDetectTwo( Prs_Man_t * p, char Sym1, char Sym2 ) -{ - char * pTemp; - for ( pTemp = p->pCur; *pTemp != ';'; pTemp++ ) - if ( *pTemp == Sym1 && *pTemp == Sym2 ) - return 1; - return 0; -} -// find closing paren -static inline char * Prs_ManFindClosingParenthesis( Prs_Man_t * p, char Open, char Close ) -{ - char * pTemp; - int Counter = 0; - int fNotName = 1; - assert( Prs_ManIsChar(p, Open) ); - for ( pTemp = p->pCur; *pTemp; pTemp++ ) - { - if ( fNotName ) - { - if ( *pTemp == Open ) - Counter++; - if ( *pTemp == Close ) - Counter--; - if ( Counter == 0 ) - return pTemp; - } - if ( *pTemp == '\\' ) - fNotName = 0; - else if ( !fNotName && *pTemp == ' ' ) - fNotName = 1; - } - return NULL; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_ManReadName( Prs_Man_t * p ) -{ - char * pStart = p->pCur; - if ( Prs_ManIsChar(p, '\\') ) // escaped name - { - pStart = ++p->pCur; - while ( !Prs_ManIsChar(p, ' ') ) - p->pCur++; - } - else if ( Prs_CharIsSymb1(*p->pCur) ) // simple name - { - p->pCur++; - while ( Prs_CharIsSymb2(*p->pCur) ) - p->pCur++; - } - else - return 0; - return Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur, NULL ); -} -static inline int Prs_ManReadNameList( Prs_Man_t * p, Vec_Int_t * vTemp, char LastSymb ) -{ - Vec_IntClear( vTemp ); - while ( 1 ) - { - 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 Prs_ManErrorSet(p, "Error number 2.", 0); - } - return 1; -} -static inline int Prs_ManReadConstant( Prs_Man_t * p ) -{ - char * pStart = p->pCur; - assert( Prs_ManIsDigit(p) ); - while ( Prs_ManIsDigit(p) ) - p->pCur++; - if ( !Prs_ManIsChar(p, '\'') ) - return Abc_NamStrFindOrAddLim( p->pFuns, pStart, p->pCur, NULL ); - p->pCur++; - if ( Prs_ManIsChar(p, 's') ) - p->pCur++; - if ( Prs_ManIsChar(p, 'b') ) - { - p->pCur++; - while ( Prs_CharIsDigitB(*p->pCur) ) - { - if ( *p->pCur == '0' ) - p->pNtk->fHasC0s = 1; - else if ( *p->pCur == '1' ) - p->pNtk->fHasC1s = 1; - else if ( *p->pCur == 'x' ) - p->pNtk->fHasCXs = 1; - else if ( *p->pCur == 'z' ) - p->pNtk->fHasCZs = 1; - p->pCur++; - } - } - else if ( Prs_ManIsChar(p, 'h') ) - { - p->pCur++; - p->pNtk->fHasC0s = 1; - while ( Prs_CharIsDigitH(*p->pCur) ) - { - if ( *p->pCur != '0' ) - p->pNtk->fHasC1s = 1; - p->pCur++; - } - } - else if ( Prs_ManIsChar(p, 'd') ) - { - p->pCur++; - p->pNtk->fHasC0s = 1; - while ( Prs_ManIsDigit(p) ) - { - if ( *p->pCur != '0' ) - p->pNtk->fHasC1s = 1; - p->pCur++; - } - } - else return Prs_ManErrorSet(p, "Cannot read radix of constant.", 0); - return Abc_NamStrFindOrAddLim( p->pFuns, pStart, p->pCur, NULL ); -} -static inline int Prs_ManReadRange( Prs_Man_t * p ) -{ - int Left, Right; - assert( Prs_ManIsChar(p, '[') ); - p->pCur++; - 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); - Left = Right = atoi(p->pCur); - while ( Prs_ManIsDigit(p) ) - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 4.", 0); - if ( Prs_ManIsChar(p, ':') ) - { - p->pCur++; - 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); - Right = atoi(p->pCur); - while ( Prs_ManIsDigit(p) ) - p->pCur++; - 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); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 6a.", 0); - return Hash_Int2ManInsert( p->vHash, Left, Right, 0 ); -} -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 Prs_ManErrorSet(p, "Error number 7.", 0); - // check final - assert( Prs_ManIsChar(p, '}') ); - p->pCur++; - // return special case - assert( Vec_IntSize(vTemp2) > 0 ); - if ( Vec_IntSize(vTemp2) == 1 ) - return Vec_IntEntry(vTemp2, 0); - return Abc_Var2Lit2( Prs_NtkAddConcat(p->pNtk, vTemp2), CBA_PRS_CONCAT ); -} -static inline int Prs_ManReadSignal( Prs_Man_t * p ) -{ - int Item; - 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 Prs_ManErrorSet(p, "Error number 10.", 0); - return Abc_Var2Lit2( Item, CBA_PRS_CONST ); - } - if ( Prs_ManIsChar(p, '{') ) - { - if ( Prs_CharIsDigit(p->pCur[1]) ) - { - p->pCur++; - if ( Prs_ManIsDigit(p) ) - { - int i, Num = atoi(p->pCur); - while ( Prs_ManIsDigit(p) ) - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); - assert( Prs_ManIsChar(p, '{') ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); - Item = Prs_ManReadSignal( p ); - assert( Prs_ManIsChar(p, '}') ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); - // add to concat all, expect the last one - assert( p->fUsingTemp2 ); - for ( i = 0; i < Num-1; i++ ) - Vec_IntPush( &p->vTemp2, Item ); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); - assert( Prs_ManIsChar(p, '}') ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 10.", 0); - return Item; - } - } - if ( p->fUsingTemp2 ) return Prs_ManErrorSet(p, "Cannot read nested concatenations.", 0); - p->fUsingTemp2 = 1; - Item = Prs_ManReadConcat(p, &p->vTemp2); - p->fUsingTemp2 = 0; - if ( Item == 0 ) return 0; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 12.", 0); - return Item; - } - else - { - Item = Prs_ManReadName( p ); - if ( Item == 0 ) return 1; // no actual name - 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 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 ); - } -} -int Prs_ManReadSignalList( Prs_Man_t * p, Vec_Int_t * vTemp, char LastSymb, int fAddForm ) -{ - Vec_IntClear( vTemp ); - while ( 1 ) - { - int Item = Prs_ManReadSignal(p); - if ( Item == 0 ) return Prs_ManErrorSet(p, "Cannot read signal in the list.", 0); - if ( fAddForm ) - Vec_IntPush( vTemp, 0 ); - 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++; - } - return 1; -} -static inline int Prs_ManReadSignalList2( Prs_Man_t * p, Vec_Int_t * vTemp ) -{ - int FormId, ActItem; - Vec_IntClear( vTemp ); - assert( Prs_ManIsChar(p, '.') ); - while ( Prs_ManIsChar(p, '.') ) - { - p->pCur++; - FormId = Prs_ManReadName( p ); - if ( FormId == 0 ) return Prs_ManErrorSet(p, "Cannot read formal name of the instance.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 17.", 0); - if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Cannot read \"(\" in the instance.", 0); - p->pCur++; - 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 an instance.", 0); - if ( !Prs_ManIsChar(p, ')') ) return Prs_ManErrorSet(p, "Cannot read \")\" in the instance.", 0); - p->pCur++; - if ( ActItem != 1 ) - Vec_IntPushTwo( vTemp, FormId, ActItem ); - 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 Prs_ManErrorSet(p, "Error number 19.", 0); - } - assert( Vec_IntSize(vTemp) > 0 ); - assert( Vec_IntSize(vTemp) % 2 == 0 ); - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_ManReadFunction( Prs_Man_t * p ) -{ - // this is a hack to read functions produced by ABC Verilog writer - p->FuncNameId = p->FuncRangeId = 0; - if ( Prs_ManUtilSkipUntilWord( p, "_func_" ) ) return Prs_ManErrorSet(p, "Cannot find \"_func_\" keyword.", 0); - p->pCur -= 6; - p->FuncNameId = Prs_ManReadName( p ); - if ( p->FuncNameId == 0 ) return Prs_ManErrorSet(p, "Error number 30a.", 0); - if ( Prs_ManUtilSkipUntilWord( p, "input" ) ) return Prs_ManErrorSet(p, "Cannot find \"input\" keyword.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 30b.", 0); - if ( Prs_ManIsChar(p, '[') ) - p->FuncRangeId = Prs_ManReadRange(p); - else if ( Prs_ManReadName(p) == PRS_VER_SIGNED ) - { - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 30c.", 0); - if ( Prs_ManIsChar(p, '[') ) - p->FuncRangeId = Prs_ManReadRange(p); - } - if ( Prs_ManUtilSkipUntilWord( p, "endfunction" ) ) return Prs_ManErrorSet(p, "Cannot find \"endfunction\" keyword.", 0); - return 1; -} -static inline int Prs_ManReadAlways( Prs_Man_t * p ) -{ - // this is a hack to read always-statement representing case-statement - int iToken; - char * pClose; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23.", 0); - if ( !Prs_ManIsChar(p, '@') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - pClose = Prs_ManFindClosingParenthesis( p, '(', ')' ); - if ( pClose == NULL ) - return Prs_ManErrorSet(p, "Expecting closing parenthesis 1.", 0); - p->pCur = pClose; - if ( !Prs_ManIsChar(p, ')') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - // read begin - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - iToken = Prs_ManReadName( p ); - if ( iToken != PRS_VER_BEGIN ) return Prs_ManErrorSet(p, "Cannot read \"begin\" keyword.", 0); - // read case - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - iToken = Prs_ManReadName( p ); - if ( iToken != PRS_VER_CASE ) return Prs_ManErrorSet(p, "Cannot read \"case\" keyword.", 0); - // read control - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - iToken = Prs_ManReadSignal( p ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read output in assign-statement.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, ')') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - // save control - Vec_IntClear( &p->vTemp3 ); - Vec_IntPushTwo( &p->vTemp3, 0, 0 ); // output will go here - Vec_IntPushTwo( &p->vTemp3, 0, iToken ); - // read conditions - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsDigit(p) ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - while ( Prs_ManIsDigit(p) ) - { - while ( Prs_ManIsDigit(p) ) - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, ':') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - // read output - iToken = Prs_ManReadSignal( p ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read output in assign-statement.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, '=') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - // save output - Vec_IntWriteEntry( &p->vTemp3, 1, iToken ); - // read input - iToken = Prs_ManReadSignal( p ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read output in assign-statement.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - if ( !Prs_ManIsChar(p, ';') ) return Prs_ManErrorSet(p, "Cannot parse always statement.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - // save input - Vec_IntPushTwo( &p->vTemp3, 0, iToken ); - } - // read endcase - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - iToken = Prs_ManReadName( p ); - if ( iToken != PRS_VER_ENDCASE ) return Prs_ManErrorSet(p, "Cannot read \"endcase\" keyword.", 0); - // read end - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 0); - iToken = Prs_ManReadName( p ); - if ( iToken != PRS_VER_END ) return Prs_ManErrorSet(p, "Cannot read \"end\" keyword.", 0); - // save binary operator - Prs_NtkAddBox( p->pNtk, CBA_BOX_NMUX, 0, &p->vTemp3 ); - return 1; -} -/* -static inline int Prs_ManReadExpression( Prs_Man_t * p, int OutItem ) -{ - int InItem, fCompl = 0, fCompl2 = 0, Oper = 0; - // read output name - if ( Prs_ManIsChar(p, '~') ) - { - fCompl = 1; - p->pCur++; - } - // write output name - Vec_IntClear( &p->vTemp ); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, OutItem ); - // read first name - InItem = Prs_ManReadSignal( p ); - if ( InItem == 0 ) return Prs_ManErrorSet(p, "Cannot read first input name in the assign-statement.", 0); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, InItem ); - // check unary operator - if ( Prs_ManIsChar(p, ';') ) - { - Oper = fCompl ? CBA_BOX_INV : CBA_BOX_BUF; - Prs_NtkAddBox( p->pNtk, Oper, 0, &p->vTemp ); - return 1; - } - if ( Prs_ManIsChar(p, '&') ) - Oper = CBA_BOX_AND; - else if ( Prs_ManIsChar(p, '|') ) - Oper = CBA_BOX_OR; - else if ( Prs_ManIsChar(p, '^') ) - 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); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, InItem ); - // read third argument - if ( Oper == CBA_BOX_MUX ) - { - assert( fCompl == 0 ); - if ( !Prs_ManIsChar(p, ':') ) return Prs_ManErrorSet(p, "Expected colon in the MUX assignment.", 0); - p->pCur++; - // read third name - InItem = Prs_ManReadSignal( p ); - if ( InItem == 0 ) return Prs_ManErrorSet(p, "Cannot read third input name in the assign-statement.", 0); - Vec_IntPush( &p->vTemp, 0 ); - 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 ); - } - } - // save binary operator - Prs_NtkAddBox( p->pNtk, Oper, 0, &p->vTemp ); - return 1; -} -*/ -static inline int Prs_ManReadExpression( Prs_Man_t * p, int OutItem ) -{ - char * pClose; - int Item, Type = CBA_OBJ_NONE; - int fRotating = 0; - - // write output name - Vec_IntClear( &p->vTemp ); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, OutItem ); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - if ( Prs_ManIsChar(p, '(') ) - { - // THIS IS A HACK TO DETECT rotating shifters: try to find both << and >> on the same line - if ( Prs_ManUtilDetectTwo(p, '>', '>') && Prs_ManUtilDetectTwo(p, '<', '<') ) - fRotating = 1; - pClose = Prs_ManFindClosingParenthesis( p, '(', ')' ); - if ( pClose == NULL ) - return Prs_ManErrorSet(p, "Expecting closing parenthesis 1.", 0); - *p->pCur = *pClose = ' '; - } - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - // read constant or concatenation - if ( Prs_ManIsDigit(p) || Prs_ManIsChar(p, '{') ) - { - Item = Prs_ManReadSignal( p ); - // write constant - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - Type = CBA_BOX_BUF; - } - else if ( Prs_ManIsChar(p, '!') || Prs_ManIsChar(p, '~') || Prs_ManIsChar(p, '@') || - Prs_ManIsChar(p, '&') || Prs_ManIsChar(p, '|') || Prs_ManIsChar(p, '^') || Prs_ManIsChar(p, '-') ) - { - if ( Prs_ManIsChar(p, '!') ) - Type = CBA_BOX_LNOT; - else if ( Prs_ManIsChar(p, '~') ) - Type = CBA_BOX_INV; - else if ( Prs_ManIsChar(p, '@') ) - Type = CBA_BOX_SQRT; - else if ( Prs_ManIsChar(p, '&') ) - Type = CBA_BOX_RAND; - else if ( Prs_ManIsChar(p, '|') ) - Type = CBA_BOX_ROR; - else if ( Prs_ManIsChar(p, '^') ) - Type = CBA_BOX_RXOR; - else if ( Prs_ManIsChar(p, '-') ) - Type = CBA_BOX_MIN; - else assert( 0 ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - // skip parentheses - if ( Prs_ManIsChar(p, '(') ) - { - pClose = Prs_ManFindClosingParenthesis( p, '(', ')' ); - if ( pClose == NULL ) - return Prs_ManErrorSet(p, "Expecting closing parenthesis 2.", 0); - *p->pCur = *pClose = ' '; - } - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - // read first name - Item = Prs_ManReadSignal( p ); - if ( Item == 0 ) return Prs_ManErrorSet(p, "Cannot read name after a unary operator.", 0); - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - } - else - { - // read first name - Item = Prs_ManReadSignal( p ); - if ( Item == 0 ) return Prs_ManErrorSet(p, "Cannot read name after a binary operator.", 0); - // check if this is a recent function - if ( Abc_Lit2Var2(Item) == p->FuncNameId ) - { - int Status, nInputs, RangeSize; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Error number 24.", 0); - p->pCur++; - Status = Prs_ManReadSignalList( p, &p->vTemp, ')', 1 ); - nInputs = Vec_IntSize(&p->vTemp)/2; - RangeSize = p->FuncRangeId ? Ptr_NtkRangeSize(p->pNtk, p->FuncRangeId) : 1; - p->FuncNameId = p->FuncRangeId = 0; - if ( Status == 0 ) return 0; - if ( nInputs == 1 ) - Type = CBA_BOX_DEC; - else if ( nInputs == RangeSize + 1 ) - Type = CBA_BOX_SEL; - else if ( nInputs == (1 << RangeSize) + 1 ) - Type = CBA_BOX_NMUX; - else return Prs_ManErrorSet(p, "Cannot determine word-level operator.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - // save word-level operator - Vec_IntInsert( &p->vTemp, 0, 0 ); - Vec_IntInsert( &p->vTemp, 1, OutItem ); - Prs_NtkAddBox( p->pNtk, Type, 0, &p->vTemp ); - return 1; - } - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - assert( !Prs_ManIsChar(p, '[') ); - - // get the next symbol - if ( Prs_ManIsChar(p, ',') || Prs_ManIsChar(p, ';') ) - Type = CBA_BOX_BUF; - else if ( Prs_ManIsChar(p, '?') ) - { - p->pCur++; - Item = Prs_ManReadSignal( p ); - if ( Item == 0 ) return 0; - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - if ( !Prs_ManIsChar(p, ':') ) return Prs_ManErrorSet(p, "MUX lacks the colon symbol (:).", 0); - - p->pCur++; - Item = Prs_ManReadSignal( p ); - if ( Item == 0 ) return 0; - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - assert( Vec_IntSize(&p->vTemp) == 8 ); - //ABC_SWAP( int, Vec_IntArray(&p->vTemp)[3], Vec_IntArray(&p->vTemp)[5] ); - Type = CBA_BOX_MUX; - } - else - { - if ( p->pCur[0] == '>' && p->pCur[1] == '>' && p->pCur[2] != '>' ) p->pCur += 2, Type = fRotating ? CBA_BOX_ROTR : CBA_BOX_SHIR; - else if ( p->pCur[0] == '>' && p->pCur[1] == '>' && p->pCur[2] == '>' ) p->pCur += 3, Type = CBA_BOX_SHIRA; - else if ( p->pCur[0] == '<' && p->pCur[1] == '<' && p->pCur[2] != '<' ) p->pCur += 2, Type = fRotating ? CBA_BOX_ROTL : CBA_BOX_SHIL; - else if ( p->pCur[0] == '<' && p->pCur[1] == '<' && p->pCur[2] == '<' ) p->pCur += 3, Type = CBA_BOX_SHILA; - else if ( p->pCur[0] == '&' && p->pCur[1] != '&' ) p->pCur += 1, Type = CBA_BOX_AND; - else if ( p->pCur[0] == '|' && p->pCur[1] != '|' ) p->pCur += 1, Type = CBA_BOX_OR; - else if ( p->pCur[0] == '^' && p->pCur[1] != '^' ) p->pCur += 1, Type = CBA_BOX_XOR; - else if ( p->pCur[0] == '&' && p->pCur[1] == '&' ) p->pCur += 2, Type = CBA_BOX_LAND; - else if ( p->pCur[0] == '|' && p->pCur[1] == '|' ) p->pCur += 2, Type = CBA_BOX_LOR; - else if ( p->pCur[0] == '=' && p->pCur[1] == '=' ) p->pCur += 2, Type = CBA_BOX_EQU; - else if ( p->pCur[0] == '!' && p->pCur[1] == '=' ) p->pCur += 2, Type = CBA_BOX_NEQU; - else if ( p->pCur[0] == '<' && p->pCur[1] != '=' ) p->pCur += 1, Type = CBA_BOX_LTHAN; - else if ( p->pCur[0] == '>' && p->pCur[1] != '=' ) p->pCur += 1, Type = CBA_BOX_MTHAN; - else if ( p->pCur[0] == '<' && p->pCur[1] == '=' ) p->pCur += 2, Type = CBA_BOX_LETHAN; - else if ( p->pCur[0] == '>' && p->pCur[1] == '=' ) p->pCur += 2, Type = CBA_BOX_METHAN; - else if ( p->pCur[0] == '+' ) p->pCur += 1, Type = CBA_BOX_ADD; - else if ( p->pCur[0] == '-' ) p->pCur += 1, Type = CBA_BOX_SUB; - else if ( p->pCur[0] == '*' && p->pCur[1] != '*' ) p->pCur += 1, Type = CBA_BOX_MUL; - else if ( p->pCur[0] == '/' ) p->pCur += 1, Type = CBA_BOX_DIV; - else if ( p->pCur[0] == '%' ) p->pCur += 1, Type = CBA_BOX_MOD; - else if ( p->pCur[0] == '*' && p->pCur[1] == '*' ) p->pCur += 2, Type = CBA_BOX_POW; - else return Prs_ManErrorSet(p, "Unsupported operation.", 0); - - Item = Prs_ManReadSignal( p ); - if ( Item == 0 ) return 0; - Vec_IntPush( &p->vTemp, 0 ); - Vec_IntPush( &p->vTemp, Item ); - // for adder insert carry-in - if ( Type == CBA_BOX_ADD ) - Vec_IntInsert( &p->vTemp, 2, 0 ); - if ( Type == CBA_BOX_ADD ) - Vec_IntInsert( &p->vTemp, 3, 0 ); - } - } - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 24.", 0); - // make sure there is nothing left there - if ( fRotating ) - { - Prs_ManUtilSkipUntilWord(p, ";"); - p->pCur--; - } - else if ( !Prs_ManIsChar(p, ',') && !Prs_ManIsChar(p, ';') ) return Prs_ManErrorSet(p, "Trailing symbols on this line.", 0); - // save binary operator - Prs_NtkAddBox( p->pNtk, Type, 0, &p->vTemp ); - return 1; -} -static inline int Prs_ManReadDeclaration( Prs_Man_t * p, int Type ) -{ - int i, Item = 0, NameId, RangeId = 0, fSigned = 0; - 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 ); - // read first word - 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); - Item = Prs_ManReadName(p); - if ( Item == PRS_VER_SIGNED ) - { - fSigned = 1; - 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); - Item = Prs_ManReadName(p); - } - if ( Item == PRS_VER_WIRE ) - { - 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); - Item = Prs_ManReadName(p); - } - // read variable names - Vec_IntClear( &p->vTemp3 ); - while ( 1 ) - { - if ( Item == 0 ) return Prs_ManErrorSet(p, "Cannot read name in the list.", 0); - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 22a", 0); - if ( Item == PRS_VER_WIRE ) - continue; - Vec_IntPush( &p->vTemp3, Item ); - if ( Prs_ManIsChar(p, '=') ) - { - if ( Type == PRS_VER_INPUT ) return Prs_ManErrorSet(p, "Input cannot be defined", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23.", 0); - if ( !Prs_ManReadExpression(p, Abc_Var2Lit2(Item, CBA_PRS_NAME)) ) - return 0; - } - if ( Prs_ManIsChar(p, ';') ) - break; - if ( !Prs_ManIsChar(p, ',') ) return Prs_ManErrorSet(p, "Expecting comma in the list.", 0); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 22b.", 0); - Item = Prs_ManReadName(p); - } - Vec_IntForEachEntry( &p->vTemp3, NameId, i ) - { - Vec_IntPush( vNames[Type - PRS_VER_INPUT], NameId ); - Vec_IntPush( vNamesR[Type - PRS_VER_INPUT], Abc_Var2Lit(RangeId, fSigned) ); - if ( Type < PRS_VER_WIRE ) - Vec_IntPush( &p->pNtk->vOrder, Abc_Var2Lit2(NameId, Type) ); - } - return 1; -} -static inline int Prs_ManReadInstance( Prs_Man_t * p, int Func ) -{ - int InstId, Status; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 25.", 0); - if ( Prs_ManIsChar(p, '#') ) - { - p->pCur++; - while ( Prs_ManIsDigit(p) ) - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 25.", 0); - } - if ( (InstId = Prs_ManReadName(p)) ) - 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 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_ManIsVerilogPrim(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 Prs_ManErrorSet(p, "Error number 28.", 0); - assert( Prs_ManIsChar(p, ')') ); - p->pCur++; - 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 ); - return 1; -} -static inline int Prs_ManReadArguments( Prs_Man_t * p ) -{ - int iRange = 0, iType = -1; - Vec_Int_t * vSigs[3] = { &p->pNtk->vInputs, &p->pNtk->vOutputs, &p->pNtk->vInouts }; - 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 Prs_ManErrorSet(p, "Error number 30.", 0); - if ( Prs_ManIsChar(p, ')') ) - return 1; - while ( 1 ) - { - int fEscape = Prs_ManIsChar(p, '\\'); - int iName = Prs_ManReadName( p ); - int fSigned = 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 && !fEscape ) // declaration - { - iType = iName; - if ( Prs_ManIsChar(p, '[') ) - { - iRange = Prs_ManReadRange(p); - 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 Prs_ManErrorSet(p, "Error number 35.", 0); - if ( iName == PRS_VER_SIGNED ) - { - fSigned = 1; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 32.", 0); - if ( Prs_ManIsChar(p, '[') ) - { - iRange = Prs_ManReadRange(p); - 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 Prs_ManErrorSet(p, "Error number 35.", 0); - } - } - if ( iType > 0 ) - { - Vec_IntPush( vSigs[iType - PRS_VER_INPUT], iName ); - Vec_IntPush( vSigsR[iType - PRS_VER_INPUT], Abc_Var2Lit(iRange, fSigned) ); - Vec_IntPush( &p->pNtk->vOrder, Abc_Var2Lit2(iName, iType) ); - } - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 36.", 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 Prs_ManErrorSet(p, "Error number 36.", 0); - } - // check final - assert( Prs_ManIsChar(p, ')') ); - return 1; -} -// this procedure can return: -// 0 = reached end-of-file; 1 = successfully parsed; 2 = recognized as primitive; 3 = failed and skipped; 4 = error (failed and could not skip) -static inline int Prs_ManReadModule( Prs_Man_t * p ) -{ - int iToken, Status = -1, fAlways = 0; - if ( p->pNtk != NULL ) return Prs_ManErrorSet(p, "Parsing previous module is unfinished.", 4); - if ( Prs_ManUtilSkipSpaces(p) ) - { - Prs_ManErrorClear( p ); - return 0; - } - // read keyword - while ( Prs_ManIsChar(p, '`') ) - { - Prs_ManUtilSkipUntilWord(p, "\n"); - if ( Prs_ManUtilSkipSpaces(p) ) - { - Prs_ManErrorClear( p ); - return 0; - } - } - iToken = Prs_ManReadName( p ); - if ( iToken != PRS_VER_MODULE ) return Prs_ManErrorSet(p, "Cannot read \"module\" keyword.", 4); - if ( Prs_ManUtilSkipSpaces(p) ) return 4; - // read module name - iToken = Prs_ManReadName( p ); - if ( iToken == 0 ) return Prs_ManErrorSet(p, "Cannot read module name.", 4); - if ( Prs_ManIsKnownModule(Abc_NamStr(p->pStrs, iToken)) ) - { - if ( Prs_ManUtilSkipUntilWord( p, "endmodule" ) ) return Prs_ManErrorSet(p, "Cannot find \"endmodule\" keyword.", 4); - //printf( "Warning! Skipped known module \"%s\".\n", Abc_NamStr(p->pStrs, iToken) ); - Vec_IntPush( &p->vKnown, iToken ); - return 2; - } - Prs_ManInitializeNtk( p, iToken, 1 ); - // skip arguments - if ( Prs_ManUtilSkipSpaces(p) ) return 4; - if ( !Prs_ManIsChar(p, '(') ) return Prs_ManErrorSet(p, "Cannot find \"(\" in the argument declaration.", 4); - if ( !Prs_ManReadArguments(p) ) return 4; - assert( *p->pCur == ')' ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return 4; - // read declarations and instances - while ( Prs_ManIsChar(p, ';') || fAlways ) - { - if ( !fAlways ) p->pCur++; - fAlways = 0; - if ( Prs_ManUtilSkipSpaces(p) ) return 4; - iToken = Prs_ManReadName( p ); - if ( iToken == PRS_VER_ENDMODULE ) - { - Vec_IntPush( &p->vSucceeded, p->pNtk->iModuleName ); - Prs_ManFinalizeNtk( p ); - return 1; - } - if ( iToken >= PRS_VER_INPUT && iToken <= PRS_VER_REG ) // declaration - Status = Prs_ManReadDeclaration( p, iToken == PRS_VER_REG ? PRS_VER_WIRE : iToken ); - else if ( iToken == PRS_VER_REG || iToken == PRS_VER_DEFPARAM ) // unsupported keywords - Status = Prs_ManUtilSkipUntil( p, ';' ); - else // read instance - { - if ( iToken == PRS_VER_ASSIGN ) - { - // read output name - int 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 Prs_ManErrorSet(p, "Error number 23.", 0); - // read expression - while ( 1 ) - { - if ( !Prs_ManReadExpression(p, OutItem) ) return 0; - if ( Prs_ManIsChar(p, ';') ) - break; - assert( Prs_ManIsChar(p, ',') ); - p->pCur++; - if ( Prs_ManUtilSkipSpaces(p) ) return Prs_ManErrorSet(p, "Error number 23a.", 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 Prs_ManErrorSet(p, "Error number 23.", 0); - } - } - else if ( iToken == PRS_VER_ALWAYS ) - Status = Prs_ManReadAlways(p), fAlways = 1; - else if ( iToken == PRS_VER_FUNCTION ) - Status = Prs_ManReadFunction(p), fAlways = 1; - else - Status = Prs_ManReadInstance( p, iToken ); - if ( Status == 0 ) - { - return 4; - - if ( Prs_ManUtilSkipUntilWord( p, "endmodule" ) ) return Prs_ManErrorSet(p, "Cannot find \"endmodule\" keyword.", 4); - //printf( "Warning! Failed to parse \"%s\". Adding module \"%s\" as blackbox.\n", - // Abc_NamStr(p->pStrs, iToken), Abc_NamStr(p->pStrs, p->pNtk->iModuleName) ); - Vec_IntPush( &p->vFailed, p->pNtk->iModuleName ); - // cleanup - Vec_IntErase( &p->pNtk->vWires ); - Vec_IntErase( &p->pNtk->vWiresR ); - Vec_IntErase( &p->pNtk->vSlices ); - Vec_IntErase( &p->pNtk->vConcats ); - Vec_IntErase( &p->pNtk->vBoxes ); - Vec_IntErase( &p->pNtk->vObjs ); - p->fUsingTemp2 = 0; - // add - Prs_ManFinalizeNtk( p ); - Prs_ManErrorClear( p ); - return 3; - } - } - if ( !Status ) return 4; - if ( Prs_ManUtilSkipSpaces(p) ) return 4; - } - return Prs_ManErrorSet(p, "Cannot find \";\" in the module definition.", 4); -} -static inline int Prs_ManReadDesign( Prs_Man_t * p ) -{ - while ( 1 ) - { - int RetValue = Prs_ManReadModule( p ); - if ( RetValue == 0 ) // end of file - break; - if ( RetValue == 1 ) // successfully parsed - continue; - if ( RetValue == 2 ) // recognized as primitive - continue; - if ( RetValue == 3 ) // failed and skipped - continue; - if ( RetValue == 4 ) // error - return 0; - assert( 0 ); - } - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Prs_ManPrintModules( Prs_Man_t * p ) -{ - char * pName; int i; - printf( "Succeeded parsing %d models:\n", Vec_IntSize(&p->vSucceeded) ); - Prs_ManForEachNameVec( &p->vSucceeded, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); - printf( "Skipped %d known models:\n", Vec_IntSize(&p->vKnown) ); - Prs_ManForEachNameVec( &p->vKnown, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); - printf( "Skipped %d failed models:\n", Vec_IntSize(&p->vFailed) ); - Prs_ManForEachNameVec( &p->vFailed, p, pName, i ) - printf( " %s", pName ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Prs_ManReadVerilog( char * pFileName ) -{ - Vec_Ptr_t * vPrs = NULL; - Prs_Man_t * p = Prs_ManAlloc( pFileName ); - if ( p == NULL ) - return NULL; - Abc_NamStrFindOrAdd( p->pFuns, "1\'b0", NULL ); - Abc_NamStrFindOrAdd( p->pFuns, "1\'b1", NULL ); - Abc_NamStrFindOrAdd( p->pFuns, "1\'bx", NULL ); - Abc_NamStrFindOrAdd( p->pFuns, "1\'bz", NULL ); - Prs_NtkAddVerilogDirectives( p ); - Prs_ManReadDesign( p ); - Prs_ManPrintModules( p ); - if ( Prs_ManErrorPrint(p) ) - ABC_SWAP( Vec_Ptr_t *, vPrs, p->vNtks ); - Prs_ManFree( p ); - return vPrs; -} - -void Prs_ManReadVerilogTest( char * pFileName ) -{ - abctime clk = Abc_Clock(); - Vec_Ptr_t * vPrs = Prs_ManReadVerilog( pFileName ); - 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 ); - Prs_ManWriteVerilog( Extra_FileNameGenericAppend(pFileName, "_out.v"), vPrs ); -// Abc_NamPrint( Prs_ManNameMan(vPrs) ); - Prs_ManVecFree( vPrs ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Prs_CreateVerilogFindFon( 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; -} -int Prs_CreateSlice( Cba_Ntk_t * p, int iFon, Prs_Ntk_t * pNtk, int Range ) -{ - int iObj, iFonNew, NameId; - assert( Cba_FonIsReal(iFon) ); - // check existing slice - NameId = Cba_NtkNewStrId( p, Cba_ManGetSliceName(p, iFon, Range) ); - iFonNew = Cba_NtkGetMap( p, NameId ); - if ( iFonNew ) - return iFonNew; - // create slice - iObj = Cba_ObjAlloc( p, CBA_BOX_SLICE, 1, 1 ); - Cba_ObjSetName( p, iObj, NameId ); - Cba_ObjSetFinFon( p, iObj, 0, iFon ); - iFonNew = Cba_ObjFon0(p, iObj); - Cba_FonSetRange( p, iFonNew, Range ); - Cba_FonSetName( p, iFonNew, NameId ); - Cba_NtkSetMap( p, NameId, iFonNew ); - return iFonNew; -} -int Prs_CreateCatIn( Cba_Ntk_t * p, Prs_Ntk_t * pNtk, int Con ) -{ - extern int Prs_CreateSignalIn( Cba_Ntk_t * p, Prs_Ntk_t * pNtk, int Sig ); - int i, Sig, iObj, iFon, NameId, nBits = 0; - Vec_Int_t * vSigs = Prs_CatSignals(pNtk, Con); - // create input concatenation - iObj = Cba_ObjAlloc( p, CBA_BOX_CONCAT, Vec_IntSize(vSigs), 1 ); - iFon = Cba_ObjFon0(p, iObj); - //sprintf( Buffer, "_icc%d_", iObj ); - //NameId = Cba_NtkNewStrId( p, Buffer ); - NameId = Cba_NtkNewStrId( p, "_icc%d_", iObj ); - Cba_FonSetName( p, iFon, NameId ); - Cba_NtkSetMap( p, NameId, iFon ); - // set inputs - Vec_IntForEachEntry( vSigs, Sig, i ) - { - iFon = Prs_CreateSignalIn( p, pNtk, Sig ); - if ( iFon ) - Cba_ObjSetFinFon( p, iObj, i, iFon ); - if ( iFon ) - nBits += Cba_FonRangeSize( p, iFon ); - } - iFon = Cba_ObjFon0(p, iObj); - Cba_FonSetRange( p, iFon, Cba_NtkHashRange(p, nBits-1, 0) ); - return Cba_ObjFon0(p, iObj); -} -int Prs_CreateSignalIn( Cba_Ntk_t * p, Prs_Ntk_t * pNtk, int Sig ) -{ - int iFon, Value = Abc_Lit2Var2( Sig ); - Prs_ManType_t Type = (Prs_ManType_t)Abc_Lit2Att2( Sig ); - if ( !Sig ) return 0; - if ( Type == CBA_PRS_NAME ) - return Prs_CreateVerilogFindFon( p, Cba_NtkNewStrId(p, Prs_NtkStr(pNtk, Value)) ); - if ( Type == CBA_PRS_CONST ) - return Cba_FonFromConst( Value ); - if ( Type == CBA_PRS_SLICE ) - { - iFon = Prs_CreateVerilogFindFon( p, Cba_NtkNewStrId(p, Prs_NtkStr(pNtk, Prs_SliceName(pNtk, Value))) ); - if ( !iFon ) - return 0; - return Prs_CreateSlice( p, iFon, pNtk, Prs_SliceRange(pNtk, Value) ); - } - assert( Type == CBA_PRS_CONCAT ); - return Prs_CreateCatIn( p, pNtk, Value ); -} -int Prs_CreateRange( Cba_Ntk_t * p, int iFon, int NameId ) -{ - int RangeId = -Cba_NtkGetMap(p, NameId); - if ( RangeId < 0 ) // this variable is already created - return Cba_FonRangeSize( p, -RangeId ); - Cba_NtkUnsetMap( p, NameId ); - Cba_NtkSetMap( p, NameId, iFon ); - if ( RangeId == 0 ) - return 1; - assert( RangeId > 0 ); - Cba_FonSetRangeSign( p, iFon, RangeId ); - return Cba_FonRangeSize( p, iFon ); -} -void Prs_CreateSignalOut( Cba_Ntk_t * p, int iFon, Prs_Ntk_t * pNtk, int Sig ) -{ - int i, iFonNew, NameOut, RangeOut, NameId, RangeId, RangeSize, nBits = 0; - Prs_ManType_t SigType = (Prs_ManType_t)Abc_Lit2Att2( Sig ); - int SigValue = Abc_Lit2Var2( Sig ); - if ( !Sig ) return; - if ( SigType == CBA_PRS_NAME ) - { - NameId = SigValue; - if ( !strncmp(Cba_NtkStr(p, NameId), "Open_", 5) ) - return; - Cba_FonSetName( p, iFon, NameId ); - Prs_CreateRange( p, iFon, NameId ); - return; - } - // create name for this fan - NameOut = Cba_NtkNewStrId( p, "_occ%d_", iFon ); - Cba_FonSetName( p, iFon, NameOut ); - Cba_NtkSetMap( p, NameOut, iFon ); - // consider special cases - if ( SigType == CBA_PRS_SLICE ) - { - NameId = Prs_SliceName(pNtk, SigValue); - RangeId = Prs_SliceRange(pNtk, SigValue); - nBits = Cba_NtkRangeSize(p, RangeId); - // save this slice - Vec_IntPushThree( &p->vArray0, NameId, RangeId, iFon ); - } - else if ( SigType == CBA_PRS_CONCAT ) - { - Vec_Int_t * vSigs = Prs_CatSignals(pNtk, SigValue); - Vec_IntReverseOrder( vSigs ); - Vec_IntForEachEntry( vSigs, Sig, i ) - { - SigType = (Prs_ManType_t)Abc_Lit2Att2( Sig ); - SigValue = Abc_Lit2Var2( Sig ); - if ( SigType == CBA_PRS_NAME ) - { - int iObjBuf, iFonBuf; - // create buffer - NameId = SigValue; - if ( !strncmp(Cba_NtkStr(p, NameId), "Open_", 5) ) - { - nBits++; - continue; - } - iObjBuf = Cba_ObjAlloc( p, CBA_BOX_BUF, 1, 1 ); - iFonBuf = Cba_ObjFon0(p, iObjBuf); - Cba_FonSetName( p, iFonBuf, NameId ); - RangeSize = Prs_CreateRange( p, iFonBuf, NameId ); - RangeOut = Cba_NtkHashRange(p, nBits+RangeSize-1, nBits); - // create slice - iFonNew = Prs_CreateSlice( p, iFon, pNtk, RangeOut ); - Cba_ObjSetFinFon( p, iObjBuf, 0, iFonNew ); - } - else if ( SigType == CBA_PRS_SLICE ) - { - NameId = Prs_SliceName(pNtk, SigValue); - RangeId = Prs_SliceRange(pNtk, SigValue); - RangeSize = Cba_NtkRangeSize(p, RangeId); - RangeOut = Cba_NtkHashRange(p, nBits+RangeSize-1, nBits); - // create slice - iFonNew = Prs_CreateSlice( p, iFon, pNtk, RangeOut ); - // save this slice - Vec_IntPushThree( &p->vArray0, NameId, RangeId, iFonNew ); - } - else assert( 0 ); - // increment complete range - nBits += RangeSize; - } - Vec_IntReverseOrder( vSigs ); - } - else assert( 0 ); - // set the range for the output - Cba_FonHashRange( p, iFon, nBits-1, 0 ); -} - -void Prs_CreateOutConcat( Cba_Ntk_t * p, int * pSlices, int nSlices ) -{ - Vec_Int_t * vBits = &p->vArray1; - int NameId = pSlices[0]; - int RangeId = -Cba_NtkGetMap(p, NameId); - int LeftId = Cba_NtkRangeLeft( p, RangeId ); - int RightId = Cba_NtkRangeRight( p, RangeId ); - int BotId = Abc_MinInt( LeftId, RightId ); - int TopId = Abc_MaxInt( LeftId, RightId ); - int i, k, iObj, iFon, nParts, Prev, nBits; - assert( RangeId > 0 ); - Vec_IntFill( vBits, Abc_MaxInt(LeftId, RightId) + 1, 0 ); - // fill up with slices - for ( i = 0; i < nSlices; i++ ) - { - int Range = pSlices[3*i+1]; - int iFon = pSlices[3*i+2]; - int Left = Cba_NtkRangeLeft( p, Range ); - int Right = Cba_NtkRangeRight( p, Range ); - int Bot = Abc_MinInt( Left, Right ); - int Top = Abc_MaxInt( Left, Right ); - assert( NameId == pSlices[3*i+0] && iFon > 0 ); - assert( BotId <= Bot && Top <= TopId ); - for ( k = Bot; k <= Top; k++ ) - { - assert( Vec_IntEntry(vBits, k) == 0 ); - Vec_IntWriteEntry( vBits, k, iFon ); - } - } - // check how many parts we have - Prev = -1; nParts = 0; - Vec_IntForEachEntryStartStop( vBits, iFon, i, BotId, TopId+1 ) - { - if ( Prev != iFon ) - nParts++; - Prev = iFon; - } - // create new concatenation - iObj = Cba_ObjAlloc( p, CBA_BOX_CONCAT, nParts, 1 ); - iFon = Cba_ObjFon0(p, iObj); - Cba_FonSetName( p, iFon, NameId ); - Prs_CreateRange( p, iFon, NameId ); - // set inputs - k = 0; Prev = -1; nBits = 0; - Vec_IntForEachEntryStartStop( vBits, iFon, i, BotId, TopId+1 ) - { - if ( Prev == -1 || Prev == iFon ) - nBits++; - else - { - if ( Prev == 0 ) // create constant - Prev = Cba_ManNewConstZero( p, nBits ); - assert( nBits == Cba_FonRangeSize(p, Prev) ); - Cba_ObjSetFinFon( p, iObj, nParts-1-k++, Prev ); - nBits = 1; - } - Prev = iFon; - } - assert( nBits == Cba_FonRangeSize(p, Prev) ); - Cba_ObjSetFinFon( p, iObj, nParts-1-k++, Prev ); - assert( k == nParts ); -} - -// looks at multi-bit signal; if one bit is repeated, returns this bit; otherwise, returns -1 -int Prs_CreateBitSignal( Prs_Ntk_t * pNtk, int Sig ) -{ - Vec_Int_t * vSigs; - int i, SigTemp, SigOne = -1, Value = Abc_Lit2Var2( Sig ); - Prs_ManType_t Type = (Prs_ManType_t)Abc_Lit2Att2( Sig ); - if ( Type == CBA_PRS_NAME || Type == CBA_PRS_SLICE ) - return -1; - if ( Type == CBA_PRS_CONST ) - { - int fOnly0 = 1, fOnly1 = 1; - char * pConst = Prs_NtkConst(pNtk, Value); - pConst = strchr( pConst, '\'' ) + 1; - assert( *pConst == 'b' ); - while ( *++pConst ) - if ( *pConst == '0' ) - fOnly1 = 0; - else if ( *pConst == '1' ) - fOnly0 = 0; - if ( fOnly0 ) - return Abc_Var2Lit2( 1, CBA_PRS_CONST ); // const0 - if ( fOnly1 ) - return Abc_Var2Lit2( 2, CBA_PRS_CONST ); // const1 - return -1; - } - assert( Type == CBA_PRS_CONCAT ); - vSigs = Prs_CatSignals( pNtk, Value ); - Vec_IntForEachEntry( vSigs, SigTemp, i ) - { - Value = Abc_Lit2Var2( SigTemp ); - Type = (Prs_ManType_t)Abc_Lit2Att2( SigTemp ); - if ( Type != CBA_PRS_NAME ) - return -1; - if ( SigOne == -1 ) - SigOne = Value; - else if ( SigOne != Value ) - return -1; - } - assert( SigOne >= 0 ); - return Abc_Var2Lit2( SigOne, CBA_PRS_NAME ); -} - -int Prs_CreateFlopSetReset( Cba_Ntk_t * p, Prs_Ntk_t * pNtk, Vec_Int_t * vBox, int * pIndexSet, int * pIndexRst, int * pBitSet, int * pBitRst ) -{ - int iSigSet = -1, iSigRst = -1; - int IndexSet = -1, IndexRst = -1; - int FormId, ActId, k; - // mark set and reset - Cba_NtkCleanMap2( p ); - Cba_NtkSetMap2( p, Cba_NtkStrId(p, "set"), 1 ); - Cba_NtkSetMap2( p, Cba_NtkStrId(p, "reset"), 2 ); - // check the inputs - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - if ( Cba_NtkGetMap2(p, FormId) == 1 ) // set - iSigSet = ActId, IndexSet = k+1; - else if ( Cba_NtkGetMap2(p, FormId) == 2 ) // reset - iSigRst = ActId, IndexRst = k+1; - assert( iSigSet >= 0 && iSigRst >= 0 ); - if ( pIndexSet ) *pBitSet = 0; - if ( pIndexRst ) *pBitRst = 0; - if ( pBitSet ) *pBitSet = 0; - if ( pBitRst ) *pBitRst = 0; - if ( iSigSet == -1 || iSigRst == -1 ) - return 0; - iSigSet = Prs_CreateBitSignal(pNtk, iSigSet); - iSigRst = Prs_CreateBitSignal(pNtk, iSigRst); - if ( iSigSet == -1 || iSigRst == -1 ) - return 0; - if ( pIndexSet ) *pIndexSet = IndexSet; - if ( pIndexRst ) *pIndexRst = IndexRst; - if ( pBitSet ) *pBitSet = iSigSet; - if ( pBitRst ) *pBitRst = iSigRst; - return 1; -} -char * Prs_CreateDetectRamPort( Prs_Ntk_t * pNtk, Vec_Int_t * vBox, int NameRamId ) -{ - int i, FormId, ActId; - Vec_IntForEachEntryDouble( vBox, FormId, ActId, i ) - if ( FormId == NameRamId ) - return Abc_NamStr(pNtk->pStrs, Abc_Lit2Var2(ActId)); - return NULL; -} -int Prs_CreateGetMemSize( char * pName ) -{ - char * pPtr1 = strchr( pName, '_' ); - char * pPtr2 = strchr( pPtr1+1, '_' ); - int Num1 = atoi( pPtr1 + 1 ); - int Num2 = atoi( pPtr2 + 1 ); - assert( Num1 + Abc_Base2Log(Num2) < 32 ); - return (1 << Num1) * Num2; -} -Vec_Ptr_t * Prs_CreateDetectRams( Prs_Ntk_t * pNtk ) -{ - Vec_Ptr_t * vAllRams = NULL, * vRam; - Vec_Int_t * vBox, * vBoxCopy; - char * pNtkName, * pRamName; - int NameRamId = Abc_NamStrFind( pNtk->pStrs, "Ram" ); - int i, k, fWrite; - Prs_NtkForEachBox( pNtk, vBox, i ) - { - if ( Prs_BoxIsNode(pNtk, i) ) // node - continue; - pNtkName = Prs_NtkStr(pNtk, Prs_BoxNtk(pNtk, i)); - fWrite = !strncmp(pNtkName, "ClockedWritePort_", strlen("ClockedWritePort_")); - if ( fWrite || !strncmp(pNtkName, "ReadPort_", strlen("ReadPort_")) ) - { - pRamName = Prs_CreateDetectRamPort( pNtk, vBox, NameRamId ); assert( pRamName ); - if ( vAllRams == NULL ) - vAllRams = Vec_PtrAlloc( 4 ); - Vec_PtrForEachEntry( Vec_Ptr_t *, vAllRams, vRam, k ) - if ( pRamName == (char *)Vec_PtrEntry(vRam, 0) ) - { - if ( fWrite ) - { - vBoxCopy = Vec_IntDup(vBox); - Vec_IntPush( vBoxCopy, i ); - Vec_PtrPush( vRam, vBoxCopy ); - } - break; - } - if ( k < Vec_PtrSize(vAllRams) ) - continue; - vRam = Vec_PtrAlloc( 4 ); - Vec_PtrPush( vRam, pRamName ); - Vec_PtrPush( vRam, Abc_Int2Ptr(Prs_CreateGetMemSize(pNtkName)) ); - if ( fWrite ) - { - vBoxCopy = Vec_IntDup(vBox); - Vec_IntPush( vBoxCopy, i ); - Vec_PtrPush( vRam, vBoxCopy ); - } - Vec_PtrPush( vAllRams, vRam ); - } - } - return vAllRams; -} -void Prs_CreateVerilogPio( Cba_Ntk_t * p, Prs_Ntk_t * pNtk ) -{ - int i, NameId, RangeId, iObj, iFon; - Cba_NtkCleanObjFuncs( p ); - Cba_NtkCleanObjNames( p ); - Cba_NtkCleanFonNames( p ); - Cba_NtkCleanFonRanges( p ); - // create inputs - Cba_NtkCleanMap( p ); - assert( Vec_IntSize(&pNtk->vInouts) == 0 ); - Vec_IntForEachEntryTwo( &pNtk->vInputs, &pNtk->vInputsR, NameId, RangeId, i ) - { - iObj = Cba_ObjAlloc( p, CBA_OBJ_PI, 0, 1 ); - Cba_ObjSetName( p, iObj, NameId ); // direct name - iFon = Cba_ObjFon0(p, iObj); - Cba_FonSetRangeSign( p, iFon, RangeId ); - Cba_FonSetName( p, iFon, NameId ); - Cba_NtkSetMap( p, NameId, iObj ); - } - // create outputs - Vec_IntForEachEntryTwo( &pNtk->vOutputs, &pNtk->vOutputsR, NameId, RangeId, i ) - { - iObj = Cba_ObjAlloc( p, CBA_OBJ_PO, 1, 0 ); - Cba_ObjSetName( p, iObj, NameId ); // direct name - Cba_NtkSetMap( p, NameId, iObj ); - } - // create order - Vec_IntForEachEntry( &pNtk->vOrder, NameId, i ) - { - iObj = Prs_CreateVerilogFindFon( p, Abc_Lit2Var2(NameId) ); // labeled name - if ( iObj ) - Vec_IntPush( &p->vOrder, iObj ); - } -} -int Prs_CreateVerilogNtk( Cba_Ntk_t * p, Prs_Ntk_t * pNtk ) -{ - Vec_Int_t * vBox2Obj = Vec_IntStart( Prs_NtkBoxNum(pNtk) ); - Vec_Int_t * vBox; Vec_Ptr_t * vAllRams, * vRam; - int i, k, iObj, iTerm, iFon, FormId, ActId, RangeId, NameId, Type; - // map inputs - Cba_NtkCleanMap( p ); - Cba_NtkForEachPi( p, iObj, i ) - Cba_NtkSetMap( p, Cba_ObjName(p, iObj), Cba_ObjFon0(p, iObj) ); - - // map wire names into their rangeID - Vec_IntForEachEntryTwo( &pNtk->vWires, &pNtk->vWiresR, NameId, RangeId, i ) - Cba_NtkSetMap( p, NameId, -RangeId ); - Vec_IntForEachEntryTwo( &pNtk->vOutputs, &pNtk->vOutputsR, NameId, RangeId, i ) - Cba_NtkSetMap( p, NameId, -RangeId ); - - // collect RAMs and create boxes - vAllRams = Prs_CreateDetectRams( pNtk ); - if ( vAllRams ) - Vec_PtrForEachEntry( Vec_Ptr_t *, vAllRams, vRam, i ) - { - char * pRamName = (char *)Vec_PtrEntry( vRam, 0 ); - int MemSize = Abc_Ptr2Int( (char *)Vec_PtrEntry( vRam, 1 ) ); - //char Buffer[1000]; sprintf( Buffer, "%s_box", pRamName ); - //NameId = Cba_NtkNewStrId( p, Buffer ); - NameId = Cba_NtkNewStrId( p, "%s_box", pRamName ); - // create RAM object - iObj = Cba_ObjAlloc( p, CBA_BOX_RAMBOX, Vec_PtrSize(vRam)-2, 1 ); - Cba_ObjSetName( p, iObj, NameId ); - iFon = Cba_ObjFon0(p, iObj); - NameId = Cba_NtkNewStrId( p, pRamName ); - Cba_FonSetName( p, iFon, NameId ); - Prs_CreateRange( p, iFon, NameId ); - assert( Cba_FonLeft(p, iFon) <= MemSize-1 ); - assert( Cba_FonRight(p, iFon) == 0 ); - //Cba_VerificSaveLineFile( p, iObj, pNet->Linefile() ); - // create write ports feeding into this object - Vec_PtrForEachEntryStart( Vec_Int_t *, vRam, vBox, k, 2 ) - { - int iObjNew = Cba_ObjAlloc( p, CBA_BOX_RAMWC, 4, 1 ); - int Line = Vec_IntPop( vBox ); - Vec_IntWriteEntry( vBox2Obj, Line, iObjNew ); - if ( Prs_BoxName(pNtk, Line) ) - Cba_ObjSetName( p, iObjNew, Prs_BoxName(pNtk, Line) ); - //Cba_VerificSaveLineFile( p, iObjNew, pInst->Linefile() ); - // connect output - iFon = Cba_ObjFon0(p, iObjNew); - Cba_FonSetRange( p, iFon, Cba_NtkHashRange(p, MemSize-1, 0) ); - //sprintf( Buffer, "%s_wp%d", pRamName, k-2 ); - //NameId = Cba_NtkNewStrId( p, Buffer ); - NameId = Cba_NtkNewStrId( p, "%s_wp%d", pRamName, k-2 ); - Cba_FonSetName( p, iFon, NameId ); - Cba_NtkSetMap( p, NameId, iFon ); - // connet to RAM object - Cba_ObjSetFinFon( p, iObj, (k++)-2, iFon ); - Vec_IntFree( vBox ); - } - Vec_PtrFree( vRam ); - } - Vec_PtrFreeP( &vAllRams ); - - // create objects - Vec_IntClear( &p->vArray0 ); - Prs_NtkForEachBox( pNtk, vBox, i ) - { - if ( Prs_BoxIsNode(pNtk, i) ) // node - { - Type = Prs_BoxNtk(pNtk, i); - iObj = Cba_ObjAlloc( p, (Cba_ObjType_t)Type, Prs_BoxIONum(pNtk, i)-1, Type == CBA_BOX_ADD ? 2 : 1 ); - Prs_CreateSignalOut( p, Cba_ObjFon0(p, iObj), pNtk, Vec_IntEntry(vBox, 1) ); // node output - } - else // box - { - Cba_Ntk_t * pBox = NULL; int nInputs, nOutputs = 1; - char ** pOutNames = NULL, * pNtkName = Prs_NtkStr(pNtk, Prs_BoxNtk(pNtk, i)); - Type = Prs_ManFindType( pNtkName, &nInputs, 1, &pOutNames ); - if ( Type == CBA_BOX_RAMWC ) - continue; - if ( Type == CBA_OBJ_BOX ) - { - pBox = Cba_ManNtkFind( p->pDesign, pNtkName ); - if ( pBox == NULL ) - { - printf( "Fatal error: Cannot find module \"%s\".\n", pNtkName ); - continue; - } - nInputs = Cba_NtkPiNum(pBox); - nOutputs = Cba_NtkPoNum(pBox); - } - else if ( Type == CBA_BOX_ADD || Type == CBA_BOX_DFFCPL ) - nOutputs = 2; - else if ( Type == CBA_BOX_NMUX ) - { - if ( !strncmp(pNtkName, "wide_mux_", strlen("wide_mux_")) ) - nInputs = 1 + (1 << atoi(pNtkName+strlen("wide_mux_"))); - else if ( !strncmp(pNtkName, "Mux_", strlen("Mux_")) ) - nInputs = 1 + (1 << atoi(pNtkName+strlen("Mux_"))); - else assert( 0 ); - } - else if ( Type == CBA_BOX_SEL ) - { - if ( !strncmp(pNtkName, "wide_select_", strlen("wide_select_")) ) - nInputs = 1 + atoi(pNtkName+strlen("wide_select_")); - else if ( !strncmp(pNtkName, "Select_", strlen("Select_")) ) - nInputs = 1 + atoi(pNtkName+strlen("Select_")); - else assert( 0 ); - } - else if ( (Type == CBA_BOX_DFFRS || Type == CBA_BOX_LATCHRS) && !strncmp(pNtkName, "wide_", strlen("wide_")) && !Prs_CreateFlopSetReset(p, pNtk, vBox, NULL, NULL, NULL, NULL) ) - nInputs = atoi(pNtkName+strlen(Type == CBA_BOX_DFFRS ? "wide_dffrs_" : "wide_latchrs_")), nOutputs = 1, Type = CBA_BOX_CONCAT; - // create object - iObj = Cba_ObjAlloc( p, (Cba_ObjType_t)Type, nInputs, nOutputs ); - if ( pBox ) Cba_ObjSetFunc( p, iObj, Cba_NtkId(pBox) ); - // mark PO objects - Cba_NtkCleanMap2( p ); - if ( pBox ) - Cba_NtkForEachPo( pBox, iTerm, k ) - Cba_NtkSetMap2( p, Cba_ObjName(pBox, iTerm), k+1 ); - else - for ( k = 0; k < nOutputs; k++ ) - Cba_NtkSetMap2( p, Cba_NtkStrId(p, pOutNames[k]), 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); - Prs_CreateSignalOut( p, iFon, pNtk, ActId ); - } - } - Vec_IntWriteEntry( vBox2Obj, i, iObj ); - if ( Prs_BoxName(pNtk, i) ) - Cba_ObjSetName( p, iObj, Prs_BoxName(pNtk, i) ); - //Cba_VerificSaveLineFile( p, iObj, pInst->Linefile() ); - } - - // create concatenations for split signals - if ( Vec_IntSize(&p->vArray0) ) - { - int Prev = -1, Index = 0; - Vec_IntSortMulti( &p->vArray0, 3, 0 ); - Vec_IntForEachEntryTriple( &p->vArray0, NameId, RangeId, iFon, i ) - { - if ( Prev != -1 && Prev != NameId ) - Prs_CreateOutConcat( p, Vec_IntArray(&p->vArray0) + Index, (i - Index)/3 ), Index = i; - Prev = NameId; - } - Prs_CreateOutConcat( p, Vec_IntArray(&p->vArray0) + Index, (i - Index)/3 ), Index = i; - //Cba_VerificSaveLineFile( p, iObj, pInst->Linefile() ); - } - - // connect objects - Prs_NtkForEachBox( pNtk, vBox, i ) - { - iObj = Vec_IntEntry( vBox2Obj, i ); - if ( Prs_BoxIsNode(pNtk, i) ) // node - { - Type = Prs_BoxNtk(pNtk, i); - Vec_IntForEachEntryDoubleStart( vBox, FormId, ActId, k, 2 ) - { - iFon = Prs_CreateSignalIn( p, pNtk, ActId ); - if ( iFon ) - Cba_ObjSetFinFon( p, iObj, k/2-1, iFon ); - } - } - else // box - { - int nInputs = -1; - char ** pInNames = NULL, * pNtkName = Prs_NtkStr(pNtk, Prs_BoxNtk(pNtk, i)); - Type = Prs_ManFindType( pNtkName, &nInputs, 0, &pInNames ); - if ( (Type == CBA_BOX_DFFRS || Type == CBA_BOX_LATCHRS) && !strncmp(pNtkName, "wide_", strlen("wide_")) ) - { - int IndexSet = -1, IndexRst = -1, iBitSet = -1, iBitRst = -1; - int Status = Prs_CreateFlopSetReset( p, pNtk, vBox, &IndexSet, &IndexRst, &iBitSet, &iBitRst ); - if ( Status ) - { - Vec_IntWriteEntry( vBox, IndexSet, iBitSet ); - Vec_IntWriteEntry( vBox, IndexRst, iBitRst ); - // updated box should be fine - } - else - { - int w, Width = atoi( pNtkName + strlen(Type == CBA_BOX_DFFRS ? "wide_dffrs_" : "wide_latchrs_") ); - assert( Cba_ObjType(p, iObj) == CBA_BOX_CONCAT ); - // prepare inputs - assert( nInputs >= 0 ); - Cba_NtkCleanMap2( p ); - for ( k = 0; k < nInputs; k++ ) - Cba_NtkSetMap2( p, Cba_NtkStrId(p, pInNames[k]), k+1 ); - // create bit-level objects - for ( w = 0; w < Width; w++ ) - { - // create bit-level flop - int iObjNew = Cba_ObjAlloc( p, (Cba_ObjType_t)Type, 4, 1 ); - if ( Prs_BoxName(pNtk, i) ) - { - NameId = Cba_NtkNewStrId( p, "%s[%d]", Prs_NtkStr(pNtk, Prs_BoxName(pNtk, i)), w ); - Cba_ObjSetName( p, iObjNew, NameId ); - } - //Cba_VerificSaveLineFile( p, iObjNew, pInst->Linefile() ); - // set output fon - iFon = Cba_ObjFon0(p, iObjNew); - { - NameId = Cba_NtkNewStrId( p, "%s[%d]", Cba_FonNameStr(p, Cba_ObjFon0(p, iObj)), w ); - Cba_FonSetName( p, iFon, NameId ); - } - // no need to map this name because it may be produced elsewhere - //Cba_NtkSetMap( p, NameId, iFon ); - // add the flop - Cba_ObjSetFinFon( p, iObj, Width-1-w, iFon ); - // create bit-level flops - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - if ( Cba_NtkGetMap2(p, FormId) ) - { - int Index = Cba_NtkGetMap2(p, FormId)-1; - iFon = Prs_CreateSignalIn( p, pNtk, ActId ); assert( iFon ); - // create bit-select node for data/set/reset (but not for clock) - if ( Index < 3 ) // not clock - iFon = Prs_CreateSlice( p, iFon, pNtk, 0 ); - Cba_ObjSetFinFon( p, iObjNew, Index, iFon ); - } - } - continue; - } - } - assert( Type == Cba_ObjType(p, iObj) ); - //assert( nInputs == -1 || nInputs == Cba_ObjFinNum(p, iObj) ); - // mark PI objects - Cba_NtkCleanMap2( p ); - if ( Type == CBA_OBJ_BOX ) - { - 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_NtkForEachPi( pBox, iTerm, k ) - Cba_NtkSetMap2( p, Cba_ObjName(pBox, iTerm), k+1 ); - } - else - { - assert( nInputs >= 0 ); - for ( k = 0; k < nInputs; k++ ) - Cba_NtkSetMap2( p, Cba_NtkStrId(p, pInNames[k]), k+1 ); - } - // connect box fins - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - if ( Cba_NtkGetMap2(p, FormId) ) - { - int Index = Cba_NtkGetMap2(p, FormId)-1; - int nBits = Cba_ObjFinNum(p, iObj); - assert( Index < nBits ); - iFon = Prs_CreateSignalIn( p, pNtk, ActId ); - if ( iFon ) - Cba_ObjSetFinFon( p, iObj, Index, iFon ); - } - // special cases - if ( Type == CBA_BOX_NMUX || Type == CBA_BOX_SEL ) - { - int FonCat = Cba_ObjFinFon( p, iObj, 1 ); - int nBits = Cba_FonRangeSize( p, FonCat ); - int nParts = Cba_ObjFinNum(p, iObj) - 1; - int Slice = nBits / nParts; - int nFins = Cba_ObjFinNum(p, iObj); - assert( Cba_ObjFinNum(p, iObj) >= 2 ); - assert( Slice * nParts == nBits ); - assert( nFins == 1 + nParts ); - Cba_ObjCleanFinFon( p, iObj, 1 ); - // create buffer for the constant - if ( FonCat < 0 ) - { - int iObjNew = Cba_ObjAlloc( p, CBA_BOX_BUF, 1, 1 ); - Cba_ObjSetFinFon( p, iObjNew, 0, FonCat ); - FonCat = Cba_ObjFon0( p, iObjNew ); - NameId = Cba_NtkNewStrId( p, "_buf_const_%d", iObjNew ); - Cba_FonSetName( p, FonCat, NameId ); - Cba_FonSetRange( p, FonCat, Cba_NtkHashRange(p, nBits-1, 0) ); - } - for ( k = 0; k < nParts; k++ ) - { -// iFon = Prs_CreateSlice( p, FonCat, pNtk, Cba_NtkHashRange(p, (nParts-1-k)*Slice+Slice-1, (nParts-1-k)*Slice) ); - iFon = Prs_CreateSlice( p, FonCat, pNtk, Cba_NtkHashRange(p, k*Slice+Slice-1, k*Slice) ); - Cba_ObjSetFinFon( p, iObj, k+1, iFon ); - } - } - } - // if carry-in is not supplied, use constant 0 - if ( Type == CBA_BOX_ADD && Cba_ObjFinFon(p, iObj, 0) == 0 ) - Cba_ObjSetFinFon( p, iObj, 0, Cba_FonFromConst(1) ); - // if set or reset are not supplied, use constant 0 - if ( Type == CBA_BOX_DFFRS && Cba_ObjFinFon(p, iObj, 1) == 0 ) - Cba_ObjSetFinFon( p, iObj, 1, Cba_FonFromConst(1) ); - if ( Type == CBA_BOX_DFFRS && Cba_ObjFinFon(p, iObj, 2) == 0 ) - Cba_ObjSetFinFon( p, iObj, 2, Cba_FonFromConst(1) ); - } - Vec_IntFree( vBox2Obj ); - // connect outputs - Vec_IntForEachEntryTwo( &pNtk->vOutputs, &pNtk->vOutputsR, NameId, RangeId, i ) - { - iObj = Cba_NtkPo( p, i ); - assert( NameId == Cba_ObjName(p, iObj) ); // direct name - iFon = Prs_CreateVerilogFindFon( p, NameId ); - if ( !iFon ) - continue; - Cba_ObjSetFinFon( p, iObj, 0, iFon ); - if ( RangeId ) - { - assert( Cba_NtkRangeLeft(p, Abc_Lit2Var(RangeId)) == Cba_FonLeft(p, iFon) ); - assert( Cba_NtkRangeRight(p, Abc_Lit2Var(RangeId)) == Cba_FonRight(p, iFon) ); - } - } - return 0; -} -Cba_Man_t * Prs_ManBuildCbaVerilog( 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 * pFuns = Abc_NamRef(pPrsRoot->pFuns); - Abc_Nam_t * pMods = Abc_NamStart( 100, 24 ); - Cba_Man_t * p = Cba_ManAlloc( pFileName, Vec_PtrSize(vDes), pStrs, pFuns, pMods, Hash_IntManRef(pPrsRoot->vHash) ); - // 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_CreateVerilogPio( pNtk, pPrsNtk ); - Cba_NtkAdd( p, pNtk ); - } - // create networks - Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pPrsNtk, i ) - { - printf( "Building module \"%s\"...\n", Prs_NtkName(pPrsNtk) ); - fError = Prs_CreateVerilogNtk( 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_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 /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaTypes.h b/src/base/cba/cbaTypes.h deleted file mode 100644 index 6fad99853..000000000 --- a/src/base/cba/cbaTypes.h +++ /dev/null @@ -1,169 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaTypes.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - July 21, 2015.] - - Revision [$Id: cbaTypes.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef ABC__base__cba__cba__types_h -#define ABC__base__cba__cba__types_h - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -// network objects -typedef enum { - CBA_OBJ_NONE = 0, // 00: unused - CBA_OBJ_PI, // 01: input - CBA_OBJ_PO, // 02: output - CBA_OBJ_BOX, // 03: box - - CBA_BOX_CF, // 04: - CBA_BOX_CT, // 05: - CBA_BOX_CX, // 06: - CBA_BOX_CZ, // 07: - - CBA_BOX_BUF, // 08: - CBA_BOX_INV, // 09: - CBA_BOX_AND, // 10: - CBA_BOX_NAND, // 11: - CBA_BOX_OR, // 12: - CBA_BOX_NOR, // 13: - CBA_BOX_XOR, // 14: - CBA_BOX_XNOR, // 15: - CBA_BOX_SHARP, // 16: - CBA_BOX_SHARPL, // 17: - CBA_BOX_MUX, // 18: - CBA_BOX_MAJ, // 19: - - CBA_BOX_ABC, // 20: - CBA_BOX_BA, // 21: - CBA_BOX_BO, // 22: - CBA_BOX_BX, // 23: - CBA_BOX_BN, // 24: - CBA_BOX_BAO, // 25: - CBA_BOX_BOA, // 26: - - CBA_BOX_RAND, // 27: - CBA_BOX_RNAND, // 28: - CBA_BOX_ROR, // 29: - CBA_BOX_RNOR, // 30: - CBA_BOX_RXOR, // 31: - CBA_BOX_RXNOR, // 32: - - CBA_BOX_LNOT, // 33 - CBA_BOX_LAND, // 34: - CBA_BOX_LNAND, // 35: - CBA_BOX_LOR, // 36: - CBA_BOX_LNOR, // 37: - CBA_BOX_LXOR, // 38: - CBA_BOX_LXNOR, // 39: - - CBA_BOX_NMUX, // 40: - CBA_BOX_SEL, // 41: - CBA_BOX_PSEL, // 42: - CBA_BOX_ENC, // 43: - CBA_BOX_PENC, // 44: - CBA_BOX_DEC, // 45: - CBA_BOX_EDEC, // 46: - - CBA_BOX_ADD, // 47: - CBA_BOX_SUB, // 48: - CBA_BOX_MUL, // 49: - CBA_BOX_SMUL, // 50: - CBA_BOX_DIV, // 51: - CBA_BOX_MOD, // 52: - CBA_BOX_REM, // 53: - CBA_BOX_POW, // 54: - CBA_BOX_MIN, // 55: - CBA_BOX_SQRT, // 56: - CBA_BOX_ABS, // 57: - - CBA_BOX_SLTHAN, // 58: - CBA_BOX_LTHAN, // 59: - CBA_BOX_LETHAN, // 60: - CBA_BOX_METHAN, // 61: - CBA_BOX_MTHAN, // 62: - CBA_BOX_EQU, // 63: - CBA_BOX_NEQU, // 64: - - CBA_BOX_SHIL, // 65: - CBA_BOX_SHIR, // 66: - CBA_BOX_SHILA, // 67: - CBA_BOX_SHIRA, // 68: - CBA_BOX_ROTL, // 69: - CBA_BOX_ROTR, // 70: - - CBA_BOX_NODE, // 71: - CBA_BOX_LUT, // 72: - CBA_BOX_GATE, // 73: - CBA_BOX_TABLE, // 74: - - CBA_BOX_TRI, // 75: - CBA_BOX_RAM, // 76: - CBA_BOX_RAMR, // 77: - CBA_BOX_RAMW, // 78: - CBA_BOX_RAMWC, // 79: - CBA_BOX_RAML, // 80: - CBA_BOX_RAMS, // 81: - CBA_BOX_RAMBOX, // 82: - - CBA_BOX_LATCH, // 83: - CBA_BOX_LATCHRS, // 84: - CBA_BOX_DFF, // 85: - CBA_BOX_DFFCPL, // 86: - CBA_BOX_DFFRS, // 87: - - CBA_BOX_SLICE, // 88: - CBA_BOX_CONCAT, // 89: - - CBA_BOX_LAST // 90 -} Cba_ObjType_t; - - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_HEADER_END - - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/base/cba/cbaWriteBlif.c b/src/base/cba/cbaWriteBlif.c deleted file mode 100644 index 9ddfe58fb..000000000 --- a/src/base/cba/cbaWriteBlif.c +++ /dev/null @@ -1,218 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaWriteBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog parser.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaWriteBlif.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" -#include "cbaPrs.h" -#include "map/mio/mio.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Writing parser state into a file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Prs_ManWriteBlifArray( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vFanins ) -{ - int i, NameId; - Vec_IntForEachEntry( vFanins, NameId, i ) - fprintf( pFile, " %s", Prs_NtkStr(p, NameId) ); - fprintf( pFile, "\n" ); -} -static void Prs_ManWriteBlifLines( FILE * pFile, Prs_Ntk_t * p ) -{ - Vec_Int_t * vBox; - int i, k, FormId, ActId; - Prs_NtkForEachBox( p, vBox, i ) - { - int NtkId = Prs_BoxNtk(p, i); - assert( Prs_BoxIONum(p, i) > 0 ); - assert( Vec_IntSize(vBox) % 2 == 0 ); - if ( NtkId == -1 ) // latch - { - fprintf( pFile, ".latch" ); - fprintf( pFile, " %s", Prs_NtkStr(p, Vec_IntEntry(vBox, 1)) ); - fprintf( pFile, " %s", Prs_NtkStr(p, Vec_IntEntry(vBox, 3)) ); - fprintf( pFile, " %c\n", '0' + Prs_BoxName(p, i) ); - } - else if ( Prs_BoxIsNode(p, i) ) // node - { - fprintf( pFile, ".names" ); - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - fprintf( pFile, " %s", Prs_NtkStr(p, ActId) ); - fprintf( pFile, "\n%s", Prs_NtkSop(p, NtkId) ); - } - else // box - { - fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", Prs_NtkStr(p, NtkId) ); - Vec_IntForEachEntryDouble( vBox, FormId, ActId, k ) - fprintf( pFile, " %s=%s", Prs_NtkStr(p, FormId), Prs_NtkStr(p, ActId) ); - fprintf( pFile, "\n" ); - } - } -} -static void Prs_ManWriteBlifNtk( FILE * pFile, Prs_Ntk_t * p ) -{ - // write header - fprintf( pFile, ".model %s\n", Prs_NtkStr(p, p->iModuleName) ); - if ( Vec_IntSize(&p->vInouts) ) - fprintf( pFile, ".inouts" ); - if ( Vec_IntSize(&p->vInouts) ) - Prs_ManWriteBlifArray( pFile, p, &p->vInouts ); - fprintf( pFile, ".inputs" ); - Prs_ManWriteBlifArray( pFile, p, &p->vInputs ); - fprintf( pFile, ".outputs" ); - Prs_ManWriteBlifArray( pFile, p, &p->vOutputs ); - // write objects - Prs_ManWriteBlifLines( pFile, p ); - fprintf( pFile, ".end\n\n" ); -} -void Prs_ManWriteBlif( char * pFileName, Vec_Ptr_t * vPrs ) -{ - Prs_Ntk_t * pNtk = Prs_ManRoot(vPrs); - FILE * pFile = fopen( pFileName, "wb" ); int i; - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "# Design \"%s\" written by ABC on %s\n\n", Prs_NtkStr(pNtk, pNtk->iModuleName), Extra_TimeStamp() ); - Vec_PtrForEachEntry( Prs_Ntk_t *, vPrs, pNtk, i ) - Prs_ManWriteBlifNtk( pFile, pNtk ); - fclose( pFile ); -} - - -/**Function************************************************************* - - Synopsis [Write elaborated design.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_ManWriteBlifLines( FILE * pFile, Cba_Ntk_t * p ) -{ - int k, iObj, iFin, iFon; - Cba_NtkForEachBox( p, iObj ) - { - if ( Cba_ObjIsBoxUser(p, iObj) ) - { - Cba_Ntk_t * pNtk = Cba_ObjNtk( p, iObj ); - fprintf( pFile, ".subckt" ); - 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, iObj) ) - { - 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_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_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 ) -{ - // write header - fprintf( pFile, ".model %s\n", Cba_NtkName(p) ); - fprintf( pFile, ".inputs" ); - Cba_ManWriteBlifArray( pFile, p, &p->vInputs ); - fprintf( pFile, ".outputs" ); - Cba_ManWriteBlifArray( pFile, p, &p->vOutputs ); - // write objects - Cba_ManWriteBlifLines( pFile, p ); - fprintf( pFile, ".end\n\n" ); -} -void Cba_ManWriteBlif( char * pFileName, Cba_Man_t * p ) -{ - FILE * pFile; - Cba_Ntk_t * pNtk; - int i; - // check the library - if ( p->pMioLib && p->pMioLib != Abc_FrameReadLibGen() ) - { - printf( "Genlib library used in the mapped design is not longer a current library.\n" ); - return; - } - pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "# Design \"%s\" written via CBA package in ABC on %s\n\n", Cba_ManName(p), Extra_TimeStamp() ); -// Cba_ManAssignInternWordNames( p ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_ManWriteBlifNtk( pFile, pNtk ); - fclose( pFile ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/cbaWriteVer.c b/src/base/cba/cbaWriteVer.c deleted file mode 100644 index 45c8ed99a..000000000 --- a/src/base/cba/cbaWriteVer.c +++ /dev/null @@ -1,1016 +0,0 @@ -/**CFile**************************************************************** - - FileName [cbaWriteVer.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Hierarchical word-level netlist.] - - Synopsis [Verilog writer.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - November 29, 2014.] - - Revision [$Id: cbaWriteVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "cba.h" -#include "cbaPrs.h" -#include "map/mio/mio.h" -#include "base/main/main.h" - -ABC_NAMESPACE_IMPL_START - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Cba_ManCreatePrimMap( char ** pMap ) -{ - memset( pMap, 0, sizeof(char *) * CBA_BOX_LAST ); - - pMap[ CBA_BOX_SLICE ] = "sli"; - pMap[ CBA_BOX_CONCAT ] = "icc"; - - pMap[ CBA_BOX_BUF ] = ""; - pMap[ CBA_BOX_INV ] = "~"; - pMap[ CBA_BOX_AND ] = "&"; - pMap[ CBA_BOX_NAND ] = "&"; - pMap[ CBA_BOX_OR ] = "|"; - pMap[ CBA_BOX_NOR ] = "|"; - pMap[ CBA_BOX_XOR ] = "^"; - pMap[ CBA_BOX_XNOR ] = "^"; - pMap[ CBA_BOX_SHARP ] = "&"; - pMap[ CBA_BOX_SHARPL ] = "&"; - pMap[ CBA_BOX_MUX ] = "?"; - pMap[ CBA_BOX_MAJ ] = "maj"; - pMap[ CBA_BOX_RAND ] = "&"; - pMap[ CBA_BOX_RNAND ] = "~&"; - pMap[ CBA_BOX_ROR ] = "|"; - pMap[ CBA_BOX_RNOR ] = "~|"; - pMap[ CBA_BOX_RXOR ] = "^"; - pMap[ CBA_BOX_RXNOR ] = "~^"; - pMap[ CBA_BOX_LNOT ] = "!"; - pMap[ CBA_BOX_LAND ] = "&&"; - pMap[ CBA_BOX_LNAND ] = "logic nand"; - pMap[ CBA_BOX_LOR ] = "||"; - pMap[ CBA_BOX_LNOR ] = "logic nor"; - pMap[ CBA_BOX_LXOR ] = "^^"; - pMap[ CBA_BOX_LXNOR ] = "logic xnor"; - pMap[ CBA_BOX_NMUX ] = "nmux"; - pMap[ CBA_BOX_SEL ] = "sel"; - pMap[ CBA_BOX_PSEL ] = "prio-select"; - pMap[ CBA_BOX_ENC ] = "enc"; - pMap[ CBA_BOX_PENC ] = "prio-enc"; - pMap[ CBA_BOX_DEC ] = "dec"; - pMap[ CBA_BOX_EDEC ] = "enable-dec"; - pMap[ CBA_BOX_ADD ] = "+"; - pMap[ CBA_BOX_SUB ] = "-"; - pMap[ CBA_BOX_MUL ] = "*"; - pMap[ CBA_BOX_DIV ] = "/"; - pMap[ CBA_BOX_MOD ] = "%"; - pMap[ CBA_BOX_REM ] = "%"; - pMap[ CBA_BOX_POW ] = "**"; - pMap[ CBA_BOX_MIN ] = "-"; - pMap[ CBA_BOX_SQRT ] = "@"; - pMap[ CBA_BOX_ABS ] = "abs"; - pMap[ CBA_BOX_LTHAN ] = "<"; - pMap[ CBA_BOX_LETHAN ] = "<="; - pMap[ CBA_BOX_METHAN ] = ">="; - pMap[ CBA_BOX_MTHAN ] = ">"; - pMap[ CBA_BOX_EQU ] = "=="; - pMap[ CBA_BOX_NEQU ] = "!="; - pMap[ CBA_BOX_SHIL ] = "<<"; - pMap[ CBA_BOX_SHIR ] = ">>"; - pMap[ CBA_BOX_SHILA ] = "<<<"; - pMap[ CBA_BOX_SHIRA ] = ">>>"; - pMap[ CBA_BOX_ROTL ] = "rotL"; - pMap[ CBA_BOX_ROTR ] = "rotR"; - - pMap[ CBA_BOX_TRI ] = "tri"; - pMap[ CBA_BOX_RAM ] = "ram"; - pMap[ CBA_BOX_RAMR ] = "ramR"; - pMap[ CBA_BOX_RAMW ] = "ramW"; - pMap[ CBA_BOX_RAMWC ] = "ramWC"; - pMap[ CBA_BOX_RAMBOX ] = "ramBox"; - - pMap[ CBA_BOX_LATCH ] = "lat"; - pMap[ CBA_BOX_LATCHRS] = "latrs"; - pMap[ CBA_BOX_DFF ] = "dff"; - pMap[ CBA_BOX_DFFRS ] = "dffrs"; -} - -/**Function************************************************************* - - Synopsis [Writing parser state into a file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Prs_NameIsLegalInVerilog( char * pName, int NameId ) -{ - // identifier ::= simple_identifier | escaped_identifier - // simple_identifier ::= [a-zA-Z_][a-zA-Z0-9_$] - // escaped_identifier ::= \ {Any_ASCII_character_except_white_space} white_space - // white_space ::= space | tab | newline - assert( pName != NULL && *pName != '\0' ); - if ( *pName == '\\' ) - return 1; - if ( NameId < 13 ) // see PRS_VER_UNKNOWN in cbaReadVer.c - return 0; - if ( (*pName < 'a' || *pName > 'z') && (*pName < 'A' || *pName > 'Z') && *pName != '_' ) - return 0; - while ( *(++pName) ) - if ( (*pName < 'a' || *pName > 'z') && (*pName < 'A' || *pName > 'Z') && (*pName < '0' || *pName > '9') && *pName != '_' && *pName != '$' ) - return 0; - return 1; -} -char * Prs_ObjGetName( Prs_Ntk_t * p, int NameId ) -{ - char * pName = Prs_NtkStr(p, NameId); - if ( pName == NULL ) - return pName; - if ( Prs_NameIsLegalInVerilog(pName, NameId) ) - return pName; - return Vec_StrPrintF( Abc_NamBuffer(p->pStrs), "\\%s ", pName ); -} -static inline char * Prs_ManWriteRange( Prs_Ntk_t * p, int RangeId, int fSlice ) -{ - int Left = RangeId ? Hash_IntObjData0( p->vHash, RangeId ) : 0; - int Right = RangeId ? Hash_IntObjData1( p->vHash, RangeId ) : 0; - if ( Left == Right && fSlice ) - return Vec_StrPrintF( Abc_NamBuffer(p->pStrs), "[%d]", Right ); - else - return Vec_StrPrintF( Abc_NamBuffer(p->pStrs), "[%d:%d]", Left, Right ); -} -static void Prs_ManWriteVerilogConcat( FILE * pFile, Prs_Ntk_t * p, int Con ) -{ - extern void Prs_ManWriteVerilogArray( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vSigs, int fOdd ); - Vec_Int_t * vSigs = Prs_CatSignals(p, Con); - fprintf( pFile, "{" ); - Prs_ManWriteVerilogArray( pFile, p, vSigs, 0 ); - fprintf( pFile, "}" ); -} -static void Prs_ManWriteVerilogSignal( FILE * pFile, Prs_Ntk_t * p, int Sig ) -{ - int Value = Abc_Lit2Var2( Sig ); - Prs_ManType_t Type = (Prs_ManType_t)Abc_Lit2Att2( Sig ); - if ( Type == CBA_PRS_NAME ) - fprintf( pFile, "%s", Prs_ObjGetName(p, Value) ); - else if ( Type == CBA_PRS_CONST ) - fprintf( pFile, "%s", Prs_NtkConst(p, Value) ); - else if ( Type == CBA_PRS_SLICE ) - fprintf( pFile, "%s%s", Prs_ObjGetName(p, Prs_SliceName(p, Value)), Prs_ManWriteRange(p, Prs_SliceRange(p, Value), 1) ); - else if ( Type == CBA_PRS_CONCAT ) - Prs_ManWriteVerilogConcat( pFile, p, Value ); - else assert( 0 ); -} -void Prs_ManWriteVerilogArray( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vSigs, int fOdd ) -{ - int i, Sig, fFirst = 1; - assert( Vec_IntSize(vSigs) > 0 ); - Vec_IntForEachEntry( vSigs, Sig, i ) - { - if ( fOdd && !(i & 1) ) - continue; - fprintf( pFile, "%s", fFirst ? "" : ", " ); - Prs_ManWriteVerilogSignal( pFile, p, Sig ); - fFirst = 0; - } -} -static void Prs_ManWriteVerilogArray2( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, FormId, ActSig; - assert( Vec_IntSize(vSigs) % 2 == 0 ); - Vec_IntForEachEntryDouble( vSigs, FormId, ActSig, i ) - { - fprintf( pFile, "." ); - fprintf( pFile, "%s", Prs_ObjGetName(p, FormId) ); - fprintf( pFile, "(" ); - Prs_ManWriteVerilogSignal( pFile, p, ActSig ); - fprintf( pFile, ")%s", (i == Vec_IntSize(vSigs) - 2) ? "" : ", " ); - } -} -static void Prs_ManWriteVerilogMux( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vSigs ) -{ - int i, FormId, ActSig; - char * pStrs[4] = { " = ", " ? ", " : ", ";\n" }; - assert( Vec_IntSize(vSigs) == 8 ); - fprintf( pFile, " assign " ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vSigs, 1) ); - fprintf( pFile, "%s", pStrs[0] ); - Vec_IntForEachEntryDoubleStart( vSigs, FormId, ActSig, i, 2 ) - { - Prs_ManWriteVerilogSignal( pFile, p, ActSig ); - fprintf( pFile, "%s", pStrs[i/2] ); - } -} -static void Prs_ManWriteVerilogBoxes( FILE * pFile, Prs_Ntk_t * p, char ** pTypeNames ) -{ - Vec_Int_t * vBox; int i, k; - Prs_NtkForEachBox( p, vBox, i ) - { - Cba_ObjType_t NtkId = (Cba_ObjType_t)Prs_BoxNtk(p, i); - //char * pNtkName = Prs_ObjGetName(p, Prs_BoxName(p, i)); - if ( NtkId == CBA_BOX_MUX && Prs_BoxIsNode(p, i) ) - Prs_ManWriteVerilogMux( pFile, p, vBox ); - else if ( Prs_BoxIsNode(p, i) ) // node - { - fprintf( pFile, " assign " ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 1) ); - fprintf( pFile, " = " ); - if ( Cba_TypeIsUnary(NtkId) ) - { - fprintf( pFile, "%s", pTypeNames[NtkId] ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 3) ); - } - else if ( NtkId == CBA_BOX_NMUX ) - { - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 3) ); - fprintf( pFile, " ? " ); - for ( k = 5; k < Vec_IntSize(vBox); k += 2 ) - { - if ( k > 5 ) fprintf( pFile, " : " ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, k) ); - } - } - else if ( NtkId == CBA_BOX_ADD ) - { - if ( Vec_IntEntry(vBox, 3) ) - { - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 3) ); - fprintf( pFile, " %s ", pTypeNames[NtkId] ); - } - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 5) ); - fprintf( pFile, " %s ", pTypeNames[NtkId] ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 7) ); - } - else - { - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 3) ); - fprintf( pFile, " %s ", pTypeNames[NtkId] ); - Prs_ManWriteVerilogSignal( pFile, p, Vec_IntEntry(vBox, 5) ); - } - fprintf( pFile, ";\n" ); - } - else // box - { - fprintf( pFile, " %s %s ( ", Prs_ObjGetName(p, NtkId), Prs_BoxName(p, i) ? Prs_ObjGetName(p, Prs_BoxName(p, i)) : "" ); - Prs_ManWriteVerilogArray2( pFile, p, vBox ); - fprintf( pFile, " );\n" ); - } - } -} -static void Prs_ManWriteVerilogIos( FILE * pFile, Prs_Ntk_t * p, int SigType ) -{ - int NameId, RangeId, i; - char * pSigNames[4] = { "inout", "input", "output", "wire" }; - Vec_Int_t * vSigs[4] = { &p->vInouts, &p->vInputs, &p->vOutputs, &p->vWires }; - Vec_Int_t * vSigsR[4] = { &p->vInoutsR, &p->vInputsR, &p->vOutputsR, &p->vWiresR }; - if ( SigType == 3 ) - fprintf( pFile, "\n" ); - Vec_IntForEachEntryTwo( vSigs[SigType], vSigsR[SigType], NameId, RangeId, i ) - { - fprintf( pFile, " %s %s%s", pSigNames[SigType], Abc_LitIsCompl(RangeId) ? "signed " : "", RangeId ? Prs_ManWriteRange(p, Abc_Lit2Var(RangeId), 0) : "" ); - fprintf( pFile, "%s;\n", Prs_ObjGetName(p, NameId) ); - } -} -static void Prs_ManWriteVerilogIoOrder( FILE * pFile, Prs_Ntk_t * p, Vec_Int_t * vOrder ) -{ - int i, NameId; - Vec_IntForEachEntry( vOrder, NameId, i ) - fprintf( pFile, "%s%s", Prs_ObjGetName(p, Abc_Lit2Var2(NameId)), i == Vec_IntSize(vOrder) - 1 ? "" : ", " ); -} -static void Prs_ManWriteVerilogNtk( FILE * pFile, Prs_Ntk_t * p, char ** pTypeNames ) -{ - int s; - // write header - fprintf( pFile, "module %s (\n ", Prs_ObjGetName(p, p->iModuleName) ); - Prs_ManWriteVerilogIoOrder( pFile, p, &p->vOrder ); - fprintf( pFile, "\n );\n" ); - // write declarations - for ( s = 0; s < 4; s++ ) - Prs_ManWriteVerilogIos( pFile, p, s ); - fprintf( pFile, "\n" ); - // write objects - Prs_ManWriteVerilogBoxes( pFile, p, pTypeNames ); - fprintf( pFile, "endmodule\n\n" ); -} -void Prs_ManWriteVerilog( char * pFileName, Vec_Ptr_t * vPrs ) -{ - char * pTypeNames[CBA_BOX_LAST]; - Prs_Ntk_t * pNtk = Prs_ManRoot(vPrs); int i; - FILE * pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - { - printf( "Cannot open output file \"%s\".\n", pFileName ); - return; - } - Cba_ManCreatePrimMap( pTypeNames ); - fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Prs_NtkStr(pNtk, pNtk->iModuleName), Extra_TimeStamp() ); - Vec_PtrForEachEntry( Prs_Ntk_t *, vPrs, pNtk, i ) - Prs_ManWriteVerilogNtk( pFile, pNtk, pTypeNames ); - fclose( pFile ); -} - - - - - -static inline int Cba_NameIsLegalInVerilog( char * pName, int NameId ) -{ - // identifier ::= simple_identifier | escaped_identifier - // simple_identifier ::= [a-zA-Z_][a-zA-Z0-9_$] - // escaped_identifier ::= \ {Any_ASCII_character_except_white_space} white_space - // white_space ::= space | tab | newline - assert( pName != NULL && *pName != '\0' ); - if ( *pName == '\\' ) - return 1; - if ( NameId < 13 ) // see PRS_VER_UNKNOWN in cbaReadVer.c - return 0; - if ( (*pName < 'a' || *pName > 'z') && (*pName < 'A' || *pName > 'Z') && *pName != '_' ) - return 0; - while ( *(++pName) ) - if ( (*pName < 'a' || *pName > 'z') && (*pName < 'A' || *pName > 'Z') && (*pName < '0' || *pName > '9') && *pName != '_' && *pName != '$' ) - return 0; - return 1; -} -char * Cba_ObjGetName( Cba_Ntk_t * p, int i ) -{ - char * pName = Cba_ObjNameStr(p, i); - if ( pName == NULL ) - return pName; - if ( Cba_NameIsLegalInVerilog(pName, Cba_ObjName(p, i)) ) - return pName; - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s ", pName ); -} -char * Cba_FonGetName( Cba_Ntk_t * p, int i ) -{ - char * pName = Cba_FonNameStr(p, i); - if ( pName == NULL ) - return pName; - if ( Cba_ObjType(p, Cba_FonObj(p, i)) == CBA_BOX_SLICE ) - return pName; - if ( Cba_NameIsLegalInVerilog(pName, Cba_FonName(p, i)) ) - return pName; - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s ", pName ); -} -char * Cba_ManGetSliceName( Cba_Ntk_t * p, int iFon, int RangeId ) -{ - int Left = Cba_NtkRangeLeft(p, RangeId); - int Right = Cba_NtkRangeRight(p, RangeId); - char * pName = Cba_FonNameStr(p, iFon); - if ( Cba_NameIsLegalInVerilog(pName, Cba_FonName(p, iFon)) ) - if ( Left == Right ) - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "%s[%d]", pName, Right ); - else - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "%s[%d:%d]", pName, Left, Right ); - else - if ( Left == Right ) - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s [%d]", pName, Right ); - else - return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s [%d:%d]", pName, Left, Right ); -} - -void Cba_ManWriteFonRange( Cba_Ntk_t * p, int iFon ) -{ - Vec_Str_t * vStr = &p->pDesign->vOut; - if ( !iFon || Cba_FonIsConst(iFon) || (Cba_FonRangeSize(p, iFon) == 1 && Cba_FonRight(p, iFon) == 0) ) - return; - if ( Cba_FonSigned(p, iFon) ) - Vec_StrPrintF( vStr, "signed " ); - Vec_StrPrintF( vStr, "[%d:%d] ", Cba_FonLeft(p, iFon), Cba_FonRight(p, iFon) ); -} -void Cba_ManWriteFonName( Cba_Ntk_t * p, int iFon, int fInlineConcat, int fInput ) -{ - extern void Cba_ManWriteConcat( Cba_Ntk_t * p, int iObj ); - Vec_Str_t * vStr = &p->pDesign->vOut; - if ( !iFon || (!Cba_FonIsConst(iFon) && !Cba_FonName(p, iFon)) ) - Vec_StrPrintF( vStr, "Open_%d", Cba_NtkMan(p)->nOpens++ ); -// Vec_StrPrintF( vStr, "1\'b0" ); - else if ( fInlineConcat && !Cba_FonIsConst(iFon) && Cba_ObjIsConcat(p, Cba_FonObj(p, iFon)) ) - Cba_ManWriteConcat( p, Cba_FonObj(p, iFon) ); - else - { - int Range = fInput ? Cba_FonRangeSize( p, iFon ) : 0; - if ( fInput && Range > 1 ) - Vec_StrPush( vStr, '{' ); - Vec_StrPrintStr( vStr, Cba_FonIsConst(iFon) ? Cba_NtkConst(p, Cba_FonConst(iFon)) : Cba_FonGetName(p, iFon) ); - if ( fInput && Range > 1 ) - Vec_StrPush( vStr, '}' ); - } -} -void Cba_ManWriteConcat( Cba_Ntk_t * p, int iObj ) -{ - int i, iFin, iFon; - Vec_Str_t * vStr = &p->pDesign->vOut; - assert( Cba_ObjIsConcat(p, iObj) ); - Vec_StrPush( vStr, '{' ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) - { - Vec_StrPrintStr( vStr, i ? ", " : "" ); - Cba_ManWriteFonName( p, iFon, 1, 0 ); - } - Vec_StrPush( vStr, '}' ); -} -int Cba_ManWriteLineFile( Cba_Ntk_t * p, int iObj, int FileAttr, int LineAttr ) -{ - Vec_Str_t * vStr = &p->pDesign->vOut; - int FileId = 0, LineId = 0; - if ( FileAttr && (FileId = Cba_ObjAttrValue(p, iObj, FileAttr)) ) - { - LineId = Cba_ObjAttrValue(p, iObj, LineAttr); - Vec_StrPrintF( vStr, " // %s(%d)", Cba_NtkStr(p, FileId), LineId ); - return 1; - } - return 0; -} -void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat ) -{ - Vec_Str_t * vStr = &p->pDesign->vOut; - 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) && Cba_FonName(p, iFon) == Cba_ObjName(p, iObj) ) - Vec_BitWriteEntry( vPoFons, iFon, 1 ); - // write header - Vec_StrPrintStr( vStr, "module " ); - Vec_StrPrintStr( vStr, Cba_NtkName(p) ); - Vec_StrPrintStr( vStr, fUseNewLine ? " (\n " : " ( " ); - StartPos = Vec_StrSize(vStr); - Cba_NtkForEachPioOrder( p, iObj, i ) - { - Vec_StrPrintStr( vStr, i ? ", " : "" ); - if ( Vec_StrSize(vStr) > StartPos + 70 ) - { - StartPos = Vec_StrSize(vStr); - Vec_StrPrintStr( vStr, "\n " ); - } - Vec_StrPrintStr( vStr, Cba_ObjGetName(p, iObj) ); - } - Vec_StrPrintStr( vStr, fUseNewLine ? "\n );" : " );" ); - Cba_ManWriteLineFile( p, 0, FileAttr, LineAttr ); - Vec_StrPrintStr( vStr, fUseNewLine ? "\n" : "\n\n" ); - // 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_ObjGetName(p, iObj) ); - Vec_StrPrintF( vStr, ";%*s", Offset + 40 - Vec_StrSize(vStr), "" ); - Cba_ManWriteLineFile( p, iObj, FileAttr, LineAttr ); - Vec_StrPush( vStr, '\n' ); - } - Vec_StrPrintStr( vStr, "\n" ); - // write objects - Cba_NtkForEachBox( p, iObj ) - { -// char * pNameNtk = Cba_NtkName(p); -// char * pNameInst = Cba_ObjGetName(p, iObj); - int Type = Cba_ObjType(p, iObj); - if ( Cba_ObjIsSlice(p, iObj) ) - continue; - if ( fInlineConcat && Cba_ObjIsConcat(p, iObj) ) - continue; - if ( Cba_ObjIsBoxUser(p, iObj) ) - { - Cba_Ntk_t * pNtk = Cba_ObjNtk(p, iObj); - // 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, 0 ); - Vec_StrPrintStr( vStr, ";\n" ); - } - // write box - Vec_StrPrintStr( vStr, " " ); - Vec_StrPrintStr( vStr, Cba_NtkName(pNtk) ); - Vec_StrPush( vStr, ' ' ); - if ( Cba_ObjName(p, iObj) ) - Vec_StrPrintF( vStr, "%s ", Cba_ObjGetName(p, iObj) ); - // write input binding - Vec_StrPrintStr( vStr, "( " ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) - { - Vec_StrPrintF( vStr, "%s.%s(", i ? ", " : "", Cba_ObjGetName(pNtk, Cba_NtkPi(pNtk, i)) ); - Cba_ManWriteFonName( p, iFon, fInlineConcat, 1 ); - Vec_StrPush( vStr, ')' ); - } - // write output binding - Cba_ObjForEachFon( p, iObj, iFon, i ) - { - Vec_StrPrintF( vStr, "%s.%s(", Cba_ObjFinNum(p, iObj) ? ", " : "", Cba_ObjGetName(pNtk, Cba_NtkPo(pNtk, i)) ); - Cba_ManWriteFonName( p, iFon, 0, 1 ); - Vec_StrPush( vStr, ')' ); - } - Vec_StrPrintStr( vStr, ");" ); - } - else if ( Type == CBA_BOX_RAMWC || Type == CBA_BOX_RAMBOX || Type == CBA_BOX_RAMR ) - { - int Num = (Type == CBA_BOX_RAMWC) ? 0 : (Type == CBA_BOX_RAMR ? 1 : 2); // write / read / box - char * pBoxName[3] = { "RAM_WRITE", "RAM_READ", "RAM_BOX" }; - char * pOutputs[3] = { "ram", "rdata", "out" }; - char * pInputs[3][4] = { {"clk", "wen", "waddr", "wdata"}, {"ren", "raddr", "ram"}, {"in0", "in1", "in2", "in3"} }; - // write declaration for the output - int iFonOut = Cba_ObjFon0(p, iObj); - if ( Vec_BitEntry(vPoFons, iFonOut) ) - Vec_StrPrintStr( vStr, " assign " ); - else - { - Vec_StrPrintStr( vStr, " wire " ); - Cba_ManWriteFonRange( p, iFonOut ); - } - Cba_ManWriteFonName( p, iFonOut, 0, 0 ); - Vec_StrPrintStr( vStr, ";\n" ); - // write box - Vec_StrPrintF( vStr, " %s( ", pBoxName[Num] ); - Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) - { - Vec_StrPrintF( vStr, "%s.%s(", i ? ", " : "", pInputs[Num][i] ); - Cba_ManWriteFonName( p, iFon, fInlineConcat, 1 ); - Vec_StrPush( vStr, ')' ); - } - Vec_StrPrintF( vStr, "%s.%s(", Cba_ObjFinNum(p, iObj) ? ", " : "", pOutputs[Num] ); - Cba_ManWriteFonName( p, iFonOut, 0, 1 ); - Vec_StrPrintStr( 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_StrPrintF( vStr, "%sd%d", i > 1 ? ", " : "", 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_StrPrintF( vStr, " %d\'b", nBits ); - 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_StrPrintF( vStr, " = d%d;\n", i-1 ); - } - 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, iFonOut ); - } - 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 ) - { - Vec_StrPrintStr( vStr, i ? ", " : "" ); - Cba_ManWriteFonName( p, iFon, fInlineConcat, 0 ); - } - Vec_StrPrintStr( vStr, " );" ); - } - else if ( Type == CBA_BOX_DEC ) - { - int iFonIn = Cba_ObjFinFon(p, iObj, 0); - int iFonOut = Cba_ObjFon0(p, iObj); - int nBitsIn = Cba_FonRangeSize(p, iFonIn); - int nBitsOut = Cba_FonRangeSize(p, iFonOut); - assert( (1 << nBitsIn) == nBitsOut ); - // 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] i; - Vec_StrPrintStr( vStr, " input " ); - Cba_ManWriteFonRange( p, iFonIn ); - Vec_StrPrintStr( vStr, "i;\n" ); - // casez (i) - Vec_StrPrintStr( vStr, " casez(i)\n" ); - // 2'b00: res = 4'b0001; - for ( i = 0; i < (1 << nBitsIn); i++ ) - { - Vec_StrPrintF( vStr, " %d\'b", nBitsIn ); - for ( k = nBitsIn-1; k >= 0; k-- ) - Vec_StrPrintNum( vStr, (i >> k) & 1 ); - Vec_StrPrintStr( vStr, ": _func_" ); - Cba_ManWriteFonName( p, iFonOut, 0, 0 ); - Vec_StrPrintF( vStr, " = %d\'b%0*d;\n", nBitsOut, nBitsOut, 0 ); - Vec_StrWriteEntry( vStr, Vec_StrSize(vStr) - i - 3, '1' ); - } - Vec_StrPrintStr( vStr, " endcase\n" ); - Vec_StrPrintStr( vStr, " endfunction\n" ); - // assign z = res(i, o); - if ( Vec_BitEntry(vPoFons, iFonOut) ) - Vec_StrPrintStr( vStr, " assign " ); - else - { - Vec_StrPrintStr( vStr, " wire " ); - Cba_ManWriteFonRange( p, iFonOut ); - } - Cba_ManWriteFonName( p, iFonOut, fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, " = _func_" ); - Cba_ManWriteFonName( p, iFonOut, 0, 0 ); - Vec_StrPrintStr( vStr, " ( " ); - Cba_ManWriteFonName( p, iFonIn, 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 iFonSet = Cba_ObjFinFon(p, iObj, 1); - int iFonRst = Cba_ObjFinFon(p, iObj, 2); - int iFonC = Cba_ObjFinFon(p, iObj, 3); - int Range = Cba_FonRangeSize( p, iFonQ ); - assert( Cba_FonRangeSize(p, iFonSet) == 1 && Cba_FonRangeSize(p, iFonRst) == 1 ); - // 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 > 0 ) - { - Vec_StrPrintStr( vStr, " if (" ); - Cba_ManWriteFonName( p, iFonSet, 0, 0 ); - Vec_StrPrintStr( vStr, ") " ); - Cba_ManWriteFonName( p, iFonQ, 0, 0 ); - Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " ); - // value 1 - Vec_StrPrintNum( vStr, Range ); - Vec_StrPrintStr( vStr, "\'b" ); - Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '1' ); - Vec_StrPrintStr( vStr, ";\n" ); -// Vec_StrPrintF( vStr, "\'b1" ); - } - if ( iFonRst > 0 ) - { - Vec_StrPrintStr( vStr, iFonSet > 0 ? " else if (" : " if (" ); - Cba_ManWriteFonName( p, iFonRst, 0, 0 ); - Vec_StrPrintStr( vStr, ") " ); - Cba_ManWriteFonName( p, iFonQ, 0, 0 ); - Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " ); - // value 0 - Vec_StrPrintNum( vStr, Range ); - Vec_StrPrintStr( vStr, "\'b" ); - Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '0' ); - Vec_StrPrintStr( vStr, ";\n" ); -// Vec_StrPrintF( vStr, "\'b0" ); - } - Vec_StrPrintStr( vStr, (iFonSet > 0 || iFonRst > 0) ? " 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_DFFCPL ) - { - // CPL_FF#32 inst_reg( .d(s1), .arstval(s2), .arst(s3), .clk(s4), .q(s5), .qbar(s6) ); - int iFon0 = Cba_ObjFon0(p, iObj); - int iFon1 = Cba_ObjFon(p, iObj, 1); - int Range = Cba_FonRangeSize( p, iFon0 ); - if ( !Vec_BitEntry(vPoFons, iFon0) ) - { - Vec_StrPrintStr( vStr, " wire " ); - Cba_ManWriteFonRange( p, iFon0 ); - Cba_ManWriteFonName( p, iFon0, 0, 0 ); - Vec_StrPrintStr( vStr, ";\n" ); - } - if ( !Vec_BitEntry(vPoFons, iFon1) && Cba_FonName(p, iFon1) ) - { - Vec_StrPrintStr( vStr, " wire " ); - Cba_ManWriteFonRange( p, iFon1 ); - Cba_ManWriteFonName( p, iFon1, 0, 0 ); - Vec_StrPrintStr( vStr, ";\n" ); - } - Vec_StrPrintStr( vStr, " CPL_FF" ); - if ( Range > 1 ) - Vec_StrPrintF( vStr, "#%d", Range ); - Vec_StrPrintStr( vStr, " " ); - if ( Cba_ObjName(p, iObj) ) - Vec_StrPrintStr( vStr, Cba_ObjGetName(p, iObj) ); - Vec_StrPrintStr( vStr, " ( .d(" ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, "), .arstval(" ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, "), .arst(" ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 2), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, "), .clk(" ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 3), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, "), .q(" ); - Cba_ManWriteFonName( p, iFon0, fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, "), .qbar(" ); - if ( Cba_FonName(p, iFon1) ) - Cba_ManWriteFonName( p, iFon1, 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, " 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 ( Vec_BitEntry(vPoFons, iFon0) ) - Vec_StrPrintStr( vStr, " assign " ); - else - { - 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_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_ObjIsConcat(p, iObj) ) - Cba_ManWriteConcat( 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_ROTL || Type == CBA_BOX_ROTR ) - { - // wire [27:0] s4960 = (s57 >> 17) | (s57 << 11); - int Range = Cba_FonRangeSize( p, Cba_ObjFon0(p, iObj) ); - int iFinFon1 = Cba_ObjFinFon(p, iObj, 1); - Vec_StrPush( vStr, '(' ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, Type == CBA_BOX_ROTL ? " << " : " >> " ); - if ( Cba_FonIsConst(iFinFon1) ) - Vec_StrPrintNum( vStr, Cba_FonConst(iFinFon1) ); - else - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, ") | (" ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); - Vec_StrPrintStr( vStr, Type == CBA_BOX_ROTL ? " >> " : " << " ); - if ( Cba_FonIsConst(iFinFon1) ) - Vec_StrPrintNum( vStr, Range - Cba_FonConst(iFinFon1) ); - else - { - Vec_StrPush( vStr, '(' ); - Vec_StrPrintNum( vStr, Range ); - Vec_StrPrintStr( vStr, " - " ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 1), fInlineConcat, 0 ); - Vec_StrPush( vStr, ')' ); - } - Vec_StrPush( vStr, ')' ); - } - 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((Cba_ObjType_t)Type) ) - { - Vec_StrPrintStr( vStr, Cba_NtkTypeName(p, Type) ); - Cba_ManWriteFonName( p, Cba_ObjFinFon(p, iObj, 0), fInlineConcat, 0 ); - } - else if ( Cba_NtkTypeName(p, Type) ) // binary operation - { - int fCompl = (Type == CBA_BOX_NAND || Type == CBA_BOX_NOR || Type == CBA_BOX_XNOR); - if ( fCompl ) - Vec_StrPrintStr( vStr, "!(" ); - 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, 0 ); - if ( fCompl ) - Vec_StrPrintStr( vStr, ")" ); - } - else // unknown - { - char * pName = Cba_FonGetName(p, Cba_ObjFon0(p, iObj)); - Vec_StrPrintStr( vStr, "" ); - printf( "Cba_ManWriteVerilog(): In module \"%s\", cannot write object \"%s\" with output name \"%s\".\n", Cba_NtkName(p), Cba_ObjGetName(p, iObj), pName ); - } - Vec_StrPush( vStr, ';' ); - } - // write attributes - Status = Cba_ManWriteLineFile( p, iObj, FileAttr, LineAttr ); - if ( !Cba_ObjIsBoxUser(p, iObj) && Cba_ObjName(p, iObj) ) - { - if ( !Status ) - Vec_StrPrintStr( vStr, " //" ); - Vec_StrPrintStr( vStr, " name=" ); - Vec_StrPrintStr( vStr, Cba_ObjGetName(p, iObj) ); - } - Vec_StrPush( vStr, '\n' ); - } - // write remaining outputs - Cba_NtkForEachPo( p, iObj, i ) - { - iFon = Cba_ObjFinFon(p, iObj, 0); - if ( !iFon || (!Cba_FonIsConst(iFon) && Cba_FonName(p, iFon) == Cba_ObjName(p, iObj)) ) // already written - continue; - Vec_StrPrintStr( vStr, " assign " ); - Vec_StrPrintStr( vStr, Cba_ObjGetName(p, iObj) ); - Vec_StrPrintStr( vStr, " = " ); - Cba_ManWriteFonName( p, iFon, fInlineConcat, 0 ); - Vec_StrPush( vStr, ';' ); - Vec_StrPush( vStr, '\n' ); - } - Vec_StrPrintStr( vStr, "\n" ); - Vec_StrPrintStr( vStr, "endmodule\n\n" ); - Vec_BitFree( vPoFons ); -} -void Cba_ManWriteVerilog( char * pFileName, Cba_Man_t * p, int fInlineConcat ) -{ - Cba_Ntk_t * pNtk; int i; - // check the library - if ( p->pMioLib && p->pMioLib != Abc_FrameReadLibGen() ) - { - printf( "Genlib library used in the mapped design is not longer a current library.\n" ); - return; - } - Cba_ManCreatePrimMap( p->pTypeNames ); - // derive the stream - p->nOpens = 1; - Vec_StrClear( &p->vOut ); - Vec_StrClear( &p->vOut2 ); - Vec_StrPrintStr( &p->vOut, "// Design \"" ); - Vec_StrPrintStr( &p->vOut, Cba_ManName(p) ); - Vec_StrPrintStr( &p->vOut, "\" written via CBA package in ABC on " ); - Vec_StrPrintStr( &p->vOut, Extra_TimeStamp() ); - Vec_StrPrintStr( &p->vOut, "\n\n" ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_ManWriteVerilogNtk( pNtk, fInlineConcat ); - // dump into file - if ( Vec_StrSize(&p->vOut) > 0 ) - { - FILE * pFile = fopen( pFileName, "wb" ); - if ( pFile == NULL ) - printf( "Cannot open file \"%s\" for writing.\n", pFileName ); - else - { - fwrite( Vec_StrArray(&p->vOut), 1, Vec_StrSize(&p->vOut), pFile ); - fclose( pFile ); - } - } -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/base/cba/module.make b/src/base/cba/module.make deleted file mode 100644 index 6e2e57beb..000000000 --- a/src/base/cba/module.make +++ /dev/null @@ -1,8 +0,0 @@ -SRC += src/base/cba/cbaBlast.c \ - src/base/cba/cbaCba.c \ - src/base/cba/cbaCom.c \ - src/base/cba/cbaNtk.c \ - src/base/cba/cbaReadBlif.c \ - src/base/cba/cbaReadVer.c \ - src/base/cba/cbaWriteBlif.c \ - src/base/cba/cbaWriteVer.c diff --git a/src/base/main/mainInit.c b/src/base/main/mainInit.c index 652766248..98b374e15 100644 --- a/src/base/main/mainInit.c +++ b/src/base/main/mainInit.c @@ -53,10 +53,6 @@ extern void Wlc_Init( Abc_Frame_t * pAbc ); extern void Wlc_End( Abc_Frame_t * pAbc ); extern void Wln_Init( Abc_Frame_t * pAbc ); extern void Wln_End( Abc_Frame_t * pAbc ); -extern void Bac_Init( Abc_Frame_t * pAbc ); -extern void Bac_End( Abc_Frame_t * pAbc ); -extern void Cba_Init( Abc_Frame_t * pAbc ); -extern void Cba_End( Abc_Frame_t * pAbc ); extern void Pla_Init( Abc_Frame_t * pAbc ); extern void Pla_End( Abc_Frame_t * pAbc ); extern void Sim_Init( Abc_Frame_t * pAbc ); @@ -123,8 +119,6 @@ void Abc_FrameInit( Abc_Frame_t * pAbc ) Emap_Init( pAbc ); Wlc_Init( pAbc ); Wln_Init( pAbc ); - Bac_Init( pAbc ); - Cba_Init( pAbc ); Pla_Init( pAbc ); Test_Init( pAbc ); Ufar_Init( pAbc ); @@ -166,8 +160,6 @@ void Abc_FrameEnd( Abc_Frame_t * pAbc ) Scl_End( pAbc ); Wlc_End( pAbc ); Wln_End( pAbc ); - Bac_End( pAbc ); - Cba_End( pAbc ); Pla_End( pAbc ); Test_End( pAbc ); Glucose_End( pAbc ); @@ -180,4 +172,3 @@ void Abc_FrameEnd( Abc_Frame_t * pAbc ) ABC_NAMESPACE_IMPL_END - diff --git a/src/base/main/mainInt.h b/src/base/main/mainInt.h index 73b3ad2dd..3525ed015 100644 --- a/src/base/main/mainInt.h +++ b/src/base/main/mainInt.h @@ -149,8 +149,6 @@ struct Abc_Frame_t_ void * pAbcWlc; Vec_Int_t * pAbcWlcInv; void * pAbcRtl; - void * pAbcBac; - void * pAbcCba; void * pAbcPla; Abc_Nam_t * pJsonStrs; Vec_Wec_t * vJsonObjs;