Commit ee72b500 by Alan Mishchenko

Various transformations of Cba_Ntk_t.

parent 26b8116a
...@@ -100,16 +100,17 @@ struct Cba_Ntk_t_ ...@@ -100,16 +100,17 @@ struct Cba_Ntk_t_
char * pName; // name char * pName; // name
Cba_Man_t * pDesign; // design Cba_Man_t * pDesign; // design
// interface // interface
Vec_Int_t vInouts; // inouts (used by parser to store signals) Vec_Int_t vInouts; // inouts (used by parser to store signals as NameId)
Vec_Int_t vInputs; // inputs (used by parser to store signals) Vec_Int_t vInputs; // inputs (used by parser to store signals as NameId)
Vec_Int_t vOutputs; // outputs (used by parser to store signals) Vec_Int_t vOutputs; // outputs (used by parser to store signals as NameId)
Vec_Int_t vWires; // wires (used by parser to store signals) Vec_Int_t vWires; // wires (used by parser to store signals as NameId)
// objects // objects
Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t) Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t)
Vec_Int_t vFuncs; // functions (used by parser to store function) Vec_Int_t vFuncs; // functions (used by parser to store function)
Vec_Int_t vInstIds; // instance names (used by parser to store instance name as NameId) Vec_Int_t vInstIds; // instance names (used by parser to store instance name as NameId)
Vec_Int_t vFanins; // fanins (used by parser to store fanin/fanout/range as NameId) Vec_Int_t vFanins; // fanins (used by parser to store fanin/fanout/range as NameId)
// attributes // attributes
Vec_Int_t vBoxes; // box objects
Vec_Int_t vNameIds; // original names as NameId Vec_Int_t vNameIds; // original names as NameId
Vec_Int_t vRanges; // ranges as NameId Vec_Int_t vRanges; // ranges as NameId
Vec_Int_t vCopies; // copy pointers Vec_Int_t vCopies; // copy pointers
...@@ -118,15 +119,22 @@ struct Cba_Ntk_t_ ...@@ -118,15 +119,22 @@ struct Cba_Ntk_t_
static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; } static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; }
static inline int Cba_ManNtkNum( Cba_Man_t * p ) { return Vec_PtrSize(&p->vNtks) - 1; } static inline int Cba_ManNtkNum( Cba_Man_t * p ) { return Vec_PtrSize(&p->vNtks) - 1; }
static inline int Cba_ManNtkId( Cba_Man_t * p, char * pName ) { return Abc_NamStrFind(p->pModels, pName); }
static inline Cba_Ntk_t * Cba_ManNtk( Cba_Man_t * p, int i ) { assert( i > 0 ); return (Cba_Ntk_t *)Vec_PtrEntry(&p->vNtks, i); } static inline Cba_Ntk_t * Cba_ManNtk( Cba_Man_t * p, int i ) { assert( i > 0 ); return (Cba_Ntk_t *)Vec_PtrEntry(&p->vNtks, i); }
static inline Cba_Ntk_t * Cba_ManRoot( Cba_Man_t * p ) { return Cba_ManNtk(p, p->iRoot); } static inline Cba_Ntk_t * Cba_ManRoot( Cba_Man_t * p ) { return Cba_ManNtk(p, p->iRoot); }
static inline Vec_Set_t * Cba_ManMem( Cba_Man_t * p ) { return &p->Mem; } static inline Vec_Set_t * Cba_ManMem( Cba_Man_t * p ) { return &p->Mem; }
static inline int Cba_ManMemSave( Cba_Man_t * p, int * d, int s ) { return Vec_SetAppend(Cba_ManMem(p), d, s); } static inline int Cba_ManMemSave( Cba_Man_t * p, int * d, int s ) { return Vec_SetAppend(Cba_ManMem(p), d, s); }
static inline int * Cba_ManMemRead( Cba_Man_t * p, int h ) { return (int *)Vec_SetEntry(Cba_ManMem(p), h); } static inline int * Cba_ManMemRead( Cba_Man_t * p, int h ) { return h ? (int *)Vec_SetEntry(Cba_ManMem(p), h) : NULL; }
static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return p->pName; } static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return p->pName; }
static inline Cba_Man_t * Cba_NtkMan( Cba_Ntk_t * p ) { return p->pDesign; } static inline Cba_Man_t * Cba_NtkMan( Cba_Ntk_t * p ) { return p->pDesign; }
static inline int Cba_NtkObjNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFanins); } static inline int Cba_NtkObjNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFanins); }
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_NtkBoxNum( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vBoxes); }
static inline int Cba_NtkNodeNum( Cba_Ntk_t * p ) { return Cba_NtkObjNum(p) - Cba_NtkPiNum(p) - Cba_NtkPoNum(p) - Cba_NtkBoxNum(p); }
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 char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pNames, i); } static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pNames, i); }
static inline char * Cba_NtkModelStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pModels, i); } static inline char * Cba_NtkModelStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pModels, i); }
static inline char * Cba_NtkFuncStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pFuncs, i); } static inline char * Cba_NtkFuncStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pFuncs, i); }
...@@ -135,13 +143,19 @@ static inline int Cba_NtkMemSave( Cba_Ntk_t * p, int * d, int s ) { re ...@@ -135,13 +143,19 @@ static inline int Cba_NtkMemSave( Cba_Ntk_t * p, int * d, int s ) { re
static inline int * Cba_NtkMemRead( Cba_Ntk_t * p, int h ) { return Cba_ManMemRead(p->pDesign, h); } static inline int * Cba_NtkMemRead( Cba_Ntk_t * p, int h ) { return Cba_ManMemRead(p->pDesign, h); }
static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vTypes, i); } static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vTypes, i); }
static inline int Cba_ObjIsPi( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PI; }
static inline int Cba_ObjIsPo( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PO; }
static inline int Cba_ObjIsNode( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_NODE; }
static inline int Cba_ObjIsBox( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_BOX; }
static inline int Cba_ObjIsPin( Cba_Ntk_t * p, int i ) { return Cba_ObjType(p, i) == CBA_OBJ_PIN; }
static inline int Cba_ObjFuncId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vFuncs, i); } static inline int Cba_ObjFuncId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vFuncs, i); }
static inline int Cba_ObjInstId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInstIds, i); } static inline int Cba_ObjInstId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInstIds, i); }
static inline int * Cba_ObjFaninArray( Cba_Ntk_t * p, int i ) { return Cba_NtkMemRead(p, Vec_IntEntry(&p->vFanins, i)); } static inline int * Cba_ObjFaninArray( Cba_Ntk_t * p, int i ) { return Cba_NtkMemRead(p, Vec_IntEntry(&p->vFanins, i)); }
static inline int Cba_ObjFaninNum( Cba_Ntk_t * p, int i ) { return *Cba_ObjFaninArray(p, i); } static inline int Cba_ObjFaninNum( Cba_Ntk_t * p, int i ) { return *Cba_ObjFaninArray(p, i); }
static inline int * Cba_ObjFanins( Cba_Ntk_t * p, int i ) { return Cba_ObjFaninArray(p, i) + 1; } static inline int * Cba_ObjFanins( Cba_Ntk_t * p, int i ) { return Cba_ObjFaninArray(p, i) + 1; }
static inline Vec_Int_t * Cba_ObjFaninVec( Cba_Ntk_t * p, int i ) { static Vec_Int_t V; V.pArray = Cba_ObjFaninArray(p, i); V.nSize = V.nCap = *V.pArray++; return &V; } static inline Vec_Int_t * Cba_ObjFaninVec( Cba_Ntk_t * p, int i ) { static Vec_Int_t V; V.pArray = Cba_ObjFaninArray(p, i); V.nSize = V.nCap = V.pArray ? *V.pArray++ : 0; return &V; }
static inline Vec_Int_t * Cba_ObjFaninVec2( Cba_Ntk_t * p, int i ) { static Vec_Int_t W; W.pArray = Cba_ObjFaninArray(p, i); W.nSize = W.nCap = *W.pArray++; return &W; } static inline Vec_Int_t * Cba_ObjFaninVec2( Cba_Ntk_t * p, int i ) { static Vec_Int_t W; W.pArray = Cba_ObjFaninArray(p, i); W.nSize = W.nCap = W.pArray ? *W.pArray++ : 0; return &W; }
static inline Cba_Ntk_t * Cba_ObjModel( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_ManNtk(p->pDesign, Cba_ObjFuncId(p, i)); }
static inline int Cba_ObjNameId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vNameIds, i); } static inline int Cba_ObjNameId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vNameIds, i); }
static inline int Cba_ObjRangeId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vRanges, i); } static inline int Cba_ObjRangeId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vRanges, i); }
...@@ -165,6 +179,11 @@ static inline char * Cba_ObjRangeStr( Cba_Ntk_t * p, int i ) { re ...@@ -165,6 +179,11 @@ static inline char * Cba_ObjRangeStr( Cba_Ntk_t * p, int i ) { re
#define Cba_ManForEachNtk( p, pNtk, i ) \ #define Cba_ManForEachNtk( p, pNtk, i ) \
for ( i = 1; (i <= Cba_ManNtkNum(p)) && (((pNtk) = Cba_ManNtk(p, i)), 1); 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) = Vec_IntEntry(&p->vInputs, i)), 1); i++ )
#define Cba_NtkForEachPo( p, iObj, i ) \
for ( i = 0; (i < Cba_NtkPoNum(p)) && (((iObj) = Vec_IntEntry(&p->vOutputs, i)), 1); i++ )
#define Cba_NtkForEachObjType( p, Type, i ) \ #define Cba_NtkForEachObjType( p, Type, i ) \
for ( i = 0; (i < Cba_NtkObjNum(p)) && (((Type) = Cba_ObjType(p, i)), 1); i++ ) for ( i = 0; (i < Cba_NtkObjNum(p)) && (((Type) = Cba_ObjType(p, i)), 1); i++ )
#define Cba_NtkForEachObjTypeFuncFanins( p, Type, Func, vFanins, i ) \ #define Cba_NtkForEachObjTypeFuncFanins( p, Type, Func, vFanins, i ) \
...@@ -175,6 +194,43 @@ static inline char * Cba_ObjRangeStr( Cba_Ntk_t * p, int i ) { re ...@@ -175,6 +194,43 @@ static inline char * Cba_ObjRangeStr( Cba_Ntk_t * p, int i ) { re
/// FUNCTION DECLARATIONS /// /// FUNCTION DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// copy contents to the vector
static inline int Cba_ManHandleArray( Cba_Man_t * p, Vec_Int_t * vFrom )
{
int h = Vec_SetFetchH( Cba_ManMem(p), sizeof(int) * (Vec_IntSize(vFrom) + 1) );
int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p), h );
pArray[0] = Vec_IntSize(vFrom);
memcpy( pArray+1, Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
return h;
}
static inline int Cba_ManHandleBuffer( Cba_Man_t * p, int iFanin )
{
int h = Vec_SetFetchH( Cba_ManMem(p), sizeof(int) * 2 );
int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p), h );
pArray[0] = 1;
pArray[1] = iFanin;
return h;
}
static inline void Cba_ManSetupArray( Cba_Man_t * p, Vec_Int_t * vTo, Vec_Int_t * vFrom )
{
if ( Vec_IntSize(vFrom) == 0 )
return;
vTo->nSize = vTo->nCap = Vec_IntSize(vFrom);
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p), sizeof(int) * Vec_IntSize(vFrom) );
memcpy( Vec_IntArray(vTo), Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
}
static inline void Cba_ManFetchArray( Cba_Man_t * p, Vec_Int_t * vTo, int nSize )
{
if ( nSize == 0 )
return;
vTo->nSize = vTo->nCap = nSize;
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p), sizeof(int) * nSize );
memset( Vec_IntArray(vTo), 0xff, sizeof(int) * nSize );
}
// constructors desctructors
static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName ) static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName )
{ {
Cba_Ntk_t * pNtk = Vec_SetFetch( Cba_ManMem(p), sizeof(Cba_Ntk_t) ); Cba_Ntk_t * pNtk = Vec_SetFetch( Cba_ManMem(p), sizeof(Cba_Ntk_t) );
...@@ -184,18 +240,14 @@ static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName ) ...@@ -184,18 +240,14 @@ static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName )
Vec_PtrPush( &p->vNtks, pNtk ); Vec_PtrPush( &p->vNtks, pNtk );
return pNtk; return pNtk;
} }
static inline Cba_Man_t * Cba_ManAlloc( char * pFileName ) static inline Cba_Man_t * Cba_ManAlloc( char * pFileName )
{ {
Cba_Man_t * p; Cba_Man_t * p = ABC_CALLOC( Cba_Man_t, 1 );
p = ABC_CALLOC( Cba_Man_t, 1 );
// design names
p->pName = Extra_FileDesignName( pFileName ); p->pName = Extra_FileDesignName( pFileName );
p->pSpec = Abc_UtilStrsav( pFileName ); p->pSpec = Abc_UtilStrsav( pFileName );
p->pNames = Abc_NamStart( 1000, 20 ); p->pNames = Abc_NamStart( 1000, 20 );
p->pModels = Abc_NamStart( 1000, 20 ); p->pModels = Abc_NamStart( 1000, 20 );
p->pFuncs = Abc_NamStart( 1000, 20 ); p->pFuncs = Abc_NamStart( 1000, 20 );
// internal data
Vec_SetAlloc_( &p->Mem, 20 ); Vec_SetAlloc_( &p->Mem, 20 );
Vec_PtrPush( &p->vNtks, NULL ); Vec_PtrPush( &p->vNtks, NULL );
return p; return p;
...@@ -204,7 +256,6 @@ static inline void Cba_ManFree( Cba_Man_t * p ) ...@@ -204,7 +256,6 @@ static inline void Cba_ManFree( Cba_Man_t * p )
{ {
ABC_FREE( p->vNtks.pArray ); ABC_FREE( p->vNtks.pArray );
Vec_SetFree_( &p->Mem ); Vec_SetFree_( &p->Mem );
// design names
Abc_NamStop( p->pNames ); Abc_NamStop( p->pNames );
Abc_NamStop( p->pModels ); Abc_NamStop( p->pModels );
Abc_NamStop( p->pFuncs ); Abc_NamStop( p->pFuncs );
...@@ -232,6 +283,10 @@ extern void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes ); ...@@ -232,6 +283,10 @@ extern void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes );
extern Cba_Man_t * Cba_PrsReadVerilog( char * pFileName ); extern Cba_Man_t * Cba_PrsReadVerilog( char * pFileName );
/*=== cbaWriteVer.c =========================================================*/ /*=== cbaWriteVer.c =========================================================*/
extern void Cba_PrsWriteVerilog( char * pFileName, Cba_Man_t * pDes ); extern void Cba_PrsWriteVerilog( char * pFileName, Cba_Man_t * pDes );
/*=== cbaNtk.c =========================================================*/
extern void Cba_ManAssignInternNames( Cba_Man_t * p );
/*=== cbaBuild.c =========================================================*/
extern Cba_Man_t * Cba_ManBuild( Cba_Man_t * p );
......
...@@ -26,44 +26,14 @@ ABC_NAMESPACE_IMPL_START ...@@ -26,44 +26,14 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
typedef struct Int_Des_t_ Int_Des_t; /*
struct Int_Des_t_ Elaboration input data:
{ Vec_Int_t vInputs; // inputs (used by parser to store signals as NameId)
char * pName; // design name Vec_Int_t vOutputs; // outputs (used by parser to store signals as NameId)
Abc_Nam_t * pNames; // name manager Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t)
Vec_Ptr_t vModels; // models Vec_Int_t vFuncs; // functions (used by parser to store function)
}; Vec_Int_t vFanins; // fanins (used by parser to store fanin/fanout signals as NameId)
typedef struct Int_Obj_t_ Int_Obj_t; */
struct Int_Obj_t_
{
int iModel;
int iFunc;
Vec_Wrd_t vFanins;
};
typedef struct Int_Ntk_t_ Int_Ntk_t;
struct Int_Ntk_t_
{
int iName;
int nObjs;
Int_Des_t * pMan;
Vec_Ptr_t vInstances;
Vec_Wrd_t vOutputs;
Vec_Int_t vInputNames;
Vec_Int_t vOutputNames;
Vec_Int_t * vCopies;
Vec_Int_t * vCopies2;
};
static inline char * Int_DesName( Int_Des_t * p ) { return p->pName; }
static inline int Int_DesNtkNum( Int_Des_t * p ) { return Vec_PtrSize( &p->vModels ) - 1; }
static inline Int_Ntk_t * Int_DesNtk( Int_Des_t * p, int i ) { return (Int_Ntk_t *)Vec_PtrEntry( &p->vModels, i ); }
static inline char * Int_NtkName( Int_Ntk_t * p ) { return Abc_NamStr( p->pMan->pNames, p->iName ); }
static inline int Int_NtkPiNum( Int_Ntk_t * p ) { return Vec_IntSize( &p->vInputNames ); }
static inline int Int_NtkPoNum( Int_Ntk_t * p ) { return Vec_IntSize( &p->vOutputNames ); }
static inline int Int_ObjInputNum( Int_Ntk_t * p, Int_Obj_t * pObj ) { return pObj->iModel ? Int_NtkPiNum(Int_DesNtk(p->pMan, pObj->iModel)) : Vec_WrdSize(&pObj->vFanins); }
static inline int Int_ObjOutputNum( Int_Ntk_t * p, Int_Obj_t * pObj ) { return pObj->iModel ? Int_NtkPoNum(Int_DesNtk(p->pMan, pObj->iModel)) : 1; }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
...@@ -71,73 +41,7 @@ static inline int Int_ObjOutputNum( Int_Ntk_t * p, Int_Obj_t * pObj ) { ...@@ -71,73 +41,7 @@ static inline int Int_ObjOutputNum( Int_Ntk_t * p, Int_Obj_t * pObj ) {
/**Function************************************************************* /**Function*************************************************************
Synopsis [Transform Ptr into Int.] Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static int Ptr_ManCheckArray( Vec_Ptr_t * vArray )
{
if ( Vec_PtrSize(vArray) == 0 )
return 1;
if ( Abc_MaxInt(8, Vec_PtrSize(vArray)) == Vec_PtrCap(vArray) )
return 1;
assert( 0 );
return 0;
}
Vec_Int_t * Ptr_ManDumpArrayToInt( Abc_Nam_t * pNames, Vec_Ptr_t * vVec, int fNode )
{
char * pName; int i;
Vec_Int_t * vNew = Vec_IntAlloc( Vec_PtrSize(vVec) );
Vec_PtrForEachEntry( char *, vVec, pName, i )
Vec_IntPush( vNew, (fNode && i == 1) ? Abc_Ptr2Int(pName) : Abc_NamStrFind(pNames, pName) );
return vNew;
}
Vec_Ptr_t * Ptr_ManDumpArrarArrayToInt( Abc_Nam_t * pNames, Vec_Ptr_t * vNodes, int fNode )
{
Vec_Ptr_t * vNode; int i;
Vec_Ptr_t * vNew = Vec_PtrAlloc( Vec_PtrSize(vNodes) );
Vec_PtrForEachEntry( Vec_Ptr_t *, vNodes, vNode, i )
Vec_PtrPush( vNew, Ptr_ManDumpArrayToInt(pNames, vNode, fNode) );
assert( Ptr_ManCheckArray(vNew) );
return vNew;
}
Vec_Ptr_t * Ptr_ManDumpNtkToInt( Abc_Nam_t * pNames, Vec_Ptr_t * vNtk, int i )
{
Vec_Ptr_t * vNew = Vec_PtrAlloc( 5 );
assert( Abc_NamStrFind(pNames, (char *)Vec_PtrEntry(vNtk, 0)) == i );
Vec_PtrPush( vNew, Abc_Int2Ptr(i) );
Vec_PtrPush( vNew, Ptr_ManDumpArrayToInt(pNames, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), 0) );
Vec_PtrPush( vNew, Ptr_ManDumpArrayToInt(pNames, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), 0) );
Vec_PtrPush( vNew, Ptr_ManDumpArrarArrayToInt(pNames, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3), 1) );
Vec_PtrPush( vNew, Ptr_ManDumpArrarArrayToInt(pNames, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4), 0) );
assert( Ptr_ManCheckArray(vNew) );
return vNew;
}
Vec_Ptr_t * Ptr_ManDumpToInt( Vec_Ptr_t * vDes )
{
Vec_Ptr_t * vNew = Vec_PtrAlloc( Vec_PtrSize(vDes) );
Vec_Ptr_t * vNtk; int i;
// create module names
Abc_Nam_t * pNames = Abc_NamStart( 1000, 20 );
Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 )
Abc_NamStrFind( pNames, (char *)Vec_PtrEntry(vNtk, 0) );
assert( i == Abc_NamObjNumMax(pNames) );
// create resulting array
Vec_PtrPush( vNew, pNames );
Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 )
Vec_PtrPush( vNew, Ptr_ManDumpNtkToInt(pNames, vNtk, i) );
assert( Ptr_ManCheckArray(vNew) );
return vNew;
}
/**Function*************************************************************
Synopsis [Transform Ptr into Int.]
Description [] Description []
...@@ -146,202 +50,249 @@ Vec_Ptr_t * Ptr_ManDumpToInt( Vec_Ptr_t * vDes ) ...@@ -146,202 +50,249 @@ Vec_Ptr_t * Ptr_ManDumpToInt( Vec_Ptr_t * vDes )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Int_Obj_t * Int_ObjAlloc( int nFanins ) // replaces NameIds of formal names by their index in the box model
{ void Cba_RemapBox( Cba_Ntk_t * pNtk, int iBox, Vec_Int_t * vMap )
Int_Obj_t * p = (Int_Obj_t *)ABC_CALLOC( char, sizeof(Int_Obj_t) + sizeof(word) * nFanins );
p->vFanins.pArray = (word *)((char *)p + sizeof(Int_Obj_t));
p->vFanins.nCap = nFanins;
return p;
}
void Int_ObjFree( Int_Obj_t * p )
{
ABC_FREE( p );
}
Int_Ntk_t * Int_NtkAlloc( Int_Des_t * pMan, int Id, int nPis, int nPos, int nInsts )
{
Int_Ntk_t * p = ABC_CALLOC( Int_Ntk_t, 1 );
p->iName = Id;
p->nObjs = nPis + nInsts;
p->pMan = pMan;
Vec_PtrGrow( &p->vInstances, nInsts );
Vec_WrdGrow( &p->vOutputs, nPos );
Vec_IntGrow( &p->vInputNames, nPis );
Vec_IntGrow( &p->vOutputNames, nPos );
return p;
}
void Int_NtkFree( Int_Ntk_t * p )
{ {
Int_Obj_t * pObj; int i; Cba_Ntk_t * pBoxModel = Cba_ObjModel( pNtk, iBox );
Vec_PtrForEachEntry( Int_Obj_t *, &p->vInstances, pObj, i ) Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iBox );
Int_ObjFree( pObj ); int i, NameId;
ABC_FREE( p->vInstances.pArray ); // map formal names into I/O indexes
ABC_FREE( p->vOutputs.pArray ); Cba_NtkForEachPi( pBoxModel, NameId, i )
ABC_FREE( p->vInputNames.pArray ); {
ABC_FREE( p->vOutputNames.pArray ); assert( Vec_IntEntry(vMap, NameId) == -1 );
Vec_IntFreeP( &p->vCopies ); Vec_IntWriteEntry( vMap, NameId, i );
Vec_IntFreeP( &p->vCopies2 ); }
ABC_FREE( p ); Cba_NtkForEachPo( pBoxModel, NameId, i )
} {
Int_Des_t * Int_DesAlloc( char * pName, Abc_Nam_t * pNames, int nModels ) assert( Vec_IntEntry(vMap, NameId) == -1 );
{ Vec_IntWriteEntry( vMap, NameId, Cba_NtkPiNum(pBoxModel) + i );
Int_Des_t * p = ABC_CALLOC( Int_Des_t, 1 ); }
p->pName = pName; // remap box
p->pNames = pNames; assert( Vec_IntSize(vFanins) % 2 == 0 );
Vec_PtrGrow( &p->vModels, nModels ); Vec_IntForEachEntry( vFanins, NameId, i )
return p; {
assert( Vec_IntEntry(vMap, NameId) != -1 );
Vec_IntWriteEntry( vFanins, i++, Vec_IntEntry(vMap, NameId) );
}
// unmap formal inputs
Cba_NtkForEachPi( pBoxModel, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 );
Cba_NtkForEachPo( pBoxModel, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 );
} }
void Int_DesFree( Int_Des_t * p ) void Cba_RemapBoxes( Cba_Ntk_t * pNtk, Vec_Int_t * vMap )
{ {
Int_Ntk_t * pTemp; int i; int Type, iBox;
Vec_PtrForEachEntry( Int_Ntk_t *, &p->vModels, pTemp, i ) Cba_NtkForEachObjType( pNtk, Type, iBox )
Int_NtkFree( pTemp ); if ( Type == CBA_OBJ_BOX )
ABC_FREE( p ); Cba_RemapBox( pNtk, iBox, vMap );
} }
Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes, Vec_Int_t * vTemp )
// replaces formal inputs by their indixes
void Ptr_ManFindInputOutputNumbers( Int_Ntk_t * pModel, Vec_Int_t * vBox, Vec_Int_t * vMap )
{ {
int i, iFormal, iName, nPis = Int_NtkPiNum(pModel); Vec_Int_t * vFanins;
Vec_IntForEachEntry( &pModel->vInputNames, iFormal, i ) Cba_Ntk_t * pNtkNew, * pNtkBox;
Vec_IntWriteEntry( vMap, iFormal, i ); int i, iObj, ObjId, FaninId, Type, Index, NameId;
Vec_IntForEachEntry( &pModel->vOutputNames, iFormal, i ) int nBoxes = 0, nObjCount = 0, NonDriven = 0;
Vec_IntWriteEntry( vMap, iFormal, nPis+i );
Vec_IntForEachEntryDouble( vBox, iFormal, iName, i ) // map old name IDs into new object IDs
Vec_IntClear( vBoxes );
Cba_NtkForEachPi( pNtk, NameId, i )
{ {
if ( i == 0 ) continue; if ( Vec_IntEntry(vMap, NameId) != -1 )
assert( Vec_IntEntry(vMap, iFormal) >= 0 ); printf( "Primary inputs %d and %d have the same name.\n", Vec_IntEntry(vMap, NameId), i );
Vec_IntWriteEntry( vBox, i, Vec_IntEntry(vMap, iFormal) ); Vec_IntWriteEntry( vMap, NameId, nObjCount++ );
} }
Vec_IntForEachEntry( &pModel->vInputNames, iFormal, i ) Cba_NtkForEachObjType( pNtk, Type, iObj )
Vec_IntWriteEntry( vMap, iFormal, -1 );
Vec_IntForEachEntry( &pModel->vOutputNames, iFormal, i )
Vec_IntWriteEntry( vMap, iFormal, -1 );
}
void Ptr_ManConvertNtk( Int_Ntk_t * pNtk, Vec_Ptr_t * vNtk, Vec_Wrd_t * vMap, Vec_Int_t * vMap2 )
{
Vec_Int_t * vInputs = (Vec_Int_t *)Vec_PtrEntry(vNtk, 1);
Vec_Int_t * vOutputs = (Vec_Int_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_Int_t * vNode, * vBox;
Int_Ntk_t * pModel;
Int_Obj_t * pObj;
int i, k, iFormal, iName, nPis, nOffset, nNonDriven = 0;
// map primary inputs
Vec_IntForEachEntry( vInputs, iName, i )
{ {
assert( ~Vec_WrdEntry(vMap, iName) == 0 ); // driven twice vFanins = Cba_ObjFaninVec( pNtk, iObj );
Vec_WrdWriteEntry( vMap, iName, i ); if ( Type == CBA_OBJ_NODE )
}
// map internal nodes
nOffset = Vec_IntSize(vInputs);
Vec_PtrForEachEntry( Vec_Int_t *, vNodes, vNode, i )
{ {
iName = Vec_IntEntry(vNode, 0); // consider node output name
assert( ~Vec_WrdEntry(vMap, iName) == 0 ); // driven twice NameId = Vec_IntEntry( vFanins, 0 );
Vec_WrdWriteEntry( vMap, iName, nOffset + i ); if ( Vec_IntEntry(vMap, NameId) != -1 )
printf( "Node output name %d is already driven.\n", NameId );
Vec_IntWriteEntry( vMap, NameId, nObjCount++ );
} }
// map internal boxes else if ( Type == CBA_OBJ_BOX )
nOffset += Vec_PtrSize(vNodes);
Vec_PtrForEachEntry( Vec_Int_t *, vBoxes, vBox, i )
{ {
// get model name Vec_IntPush( vBoxes, nObjCount++ );
iName = Vec_IntEntry( vBox, 0 ); pNtkBox = Cba_ObjModel( pNtk, iObj );
assert( iName >= 1 && iName <= Int_DesNtkNum(pNtk->pMan) ); // bad model name Vec_IntForEachEntry( vFanins, Index, i )
pModel = Int_DesNtk( pNtk->pMan, iName );
nPis = Int_NtkPiNum( pModel );
// replace inputs/outputs by their IDs
Ptr_ManFindInputOutputNumbers( pModel, vBox, vMap2 );
// go through outputs of this box
Vec_IntForEachEntryDouble( vBox, iFormal, iName, k )
if ( k > 0 && i >= nPis ) // output
{ {
assert( ~Vec_WrdEntry(vMap, iName) == 0 ); // driven twice i++;
Vec_WrdWriteEntry( vMap, iName, (nOffset + i) | ((word)iFormal << 32) ); if ( Index < Cba_NtkPiNum(pNtkBox) )
continue;
// consider box output name
NameId = Vec_IntEntry( vFanins, i );
if ( Vec_IntEntry(vMap, NameId) != -1 )
printf( "Box output name %d is already driven.\n", NameId );
Vec_IntWriteEntry( vMap, NameId, nObjCount + Index - Cba_NtkPiNum(pNtkBox) );
}
nObjCount += Cba_NtkPoNum(pNtkBox);
} }
} }
// save input names // check non-driven nets
Vec_IntForEachEntry( vInputs, iName, i ) Cba_NtkForEachObjType( pNtk, Type, iObj )
Vec_IntPush( &pNtk->vInputNames, iName );
// create nodes with the given connectivity
Vec_PtrForEachEntry( Vec_Int_t *, vNodes, vNode, i )
{ {
pObj = Int_ObjAlloc( Vec_IntSize(vNode) - 2 ); vFanins = Cba_ObjFaninVec( pNtk, iObj );
pObj->iFunc = Vec_IntEntry(vNode, 1); if ( Type == CBA_OBJ_NODE )
Vec_IntForEachEntryStart( vNode, iName, k, 2 )
{ {
Vec_WrdPush( &pObj->vFanins, Vec_WrdEntry(vMap, iName) ); // consider node input names
nNonDriven += (~Vec_WrdEntry(vMap, iName) == 0); Vec_IntForEachEntryStart( vFanins, NameId, i, 1 )
{
if ( Vec_IntEntry(vMap, NameId) != -1 )
continue;
if ( NonDriven++ == 0 ) nObjCount++;
Vec_IntWriteEntry( vMap, NameId, nObjCount-1 );
} }
Vec_PtrPush( &pNtk->vInstances, pObj );
} }
// create boxes with the given connectivity else if ( Type == CBA_OBJ_BOX )
Vec_PtrForEachEntry( Vec_Int_t *, vBoxes, vBox, i )
{ {
pModel = Int_DesNtk( pNtk->pMan, Vec_IntEntry(vBox, 0) ); pNtkBox = Cba_ObjModel( pNtk, iObj );
nPis = Int_NtkPiNum( pModel ); Vec_IntForEachEntry( vFanins, Index, i )
pObj = Int_ObjAlloc( nPis );
Vec_IntForEachEntryDouble( vBox, iFormal, iName, k )
if ( k > 0 && iFormal < nPis ) // input
{ {
Vec_WrdPush( &pObj->vFanins, Vec_WrdEntry(vMap, iName) ); i++;
nNonDriven += (~Vec_WrdEntry(vMap, iName) == 0); if ( Index >= Cba_NtkPiNum(pNtkBox) )
continue;
// consider box input name
NameId = Vec_IntEntry( vFanins, i );
if ( Vec_IntEntry(vMap, NameId) != -1 )
continue;
if ( NonDriven++ == 0 ) nObjCount++;
Vec_IntWriteEntry( vMap, NameId, nObjCount-1 );
}
} }
Vec_PtrPush( &pNtk->vInstances, pObj );
} }
// save output names Cba_NtkForEachPo( pNtk, NameId, i )
Vec_IntForEachEntry( vOutputs, iName, i )
{ {
Vec_IntPush( &pNtk->vOutputNames, iName ); if ( Vec_IntEntry(vMap, NameId) != -1 )
Vec_WrdPush( &pNtk->vOutputs, Vec_WrdEntry(vMap, iName) ); continue;
nNonDriven += (~Vec_WrdEntry(vMap, iName) == 0); if ( NonDriven++ == 0 ) nObjCount++;
Vec_IntWriteEntry( vMap, NameId, nObjCount-1 );
} }
if ( nNonDriven ) if ( NonDriven > 0 )
printf( "Model %s has %d non-driven nets.\n", Int_NtkName(pNtk), nNonDriven ); printf( "Detected %d non-driven nets.\n", NonDriven );
} assert( NonDriven == 0 );
Int_Ntk_t * Ptr_ManConvertNtkInter( Int_Des_t * pDes, Vec_Ptr_t * vNtk, int Id )
{ // start network
Vec_Int_t * vInputs = (Vec_Int_t *)Vec_PtrEntry(vNtk, 1); pNtkNew = Cba_NtkAlloc( pNew, Cba_NtkName(pNtk) );
Vec_Int_t * vOutputs = (Vec_Int_t *)Vec_PtrEntry(vNtk, 2); Cba_ManFetchArray( pNew, &pNtkNew->vInputs, Cba_NtkPiNum(pNtk) );
Vec_Ptr_t * vNodes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3); Cba_ManFetchArray( pNew, &pNtkNew->vOutputs, Cba_NtkPoNum(pNtk) );
Vec_Ptr_t * vBoxes = (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4); Cba_ManFetchArray( pNew, &pNtkNew->vTypes, nObjCount + Cba_NtkPoNum(pNtk) );
return Int_NtkAlloc( pDes, Id, Vec_IntSize(vInputs), Vec_IntSize(vOutputs), Vec_PtrSize(vNodes) + Vec_PtrSize(vBoxes) ); Cba_ManFetchArray( pNew, &pNtkNew->vFuncs, nObjCount + Cba_NtkPoNum(pNtk) );
Cba_ManFetchArray( pNew, &pNtkNew->vFanins, nObjCount + Cba_NtkPoNum(pNtk) );
Cba_ManFetchArray( pNew, &pNtkNew->vNameIds, nObjCount + Cba_NtkPoNum(pNtk) );
Cba_ManSetupArray( pNew, &pNtkNew->vBoxes, vBoxes );
// fill object information
Cba_NtkForEachPi( pNtk, NameId, i )
{
ObjId = Vec_IntEntry( vMap, NameId );
Vec_IntWriteEntry( &pNtkNew->vInputs, i, ObjId );
Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, NameId );
}
Cba_NtkForEachObjType( pNtk, Type, iObj )
{
vFanins = Cba_ObjFaninVec( pNtk, iObj );
if ( Type == CBA_OBJ_NODE )
{
ObjId = Vec_IntEntry( vMap, Vec_IntEntry(vFanins, 0) );
Vec_IntClear( vTemp );
Vec_IntForEachEntryStart( vFanins, NameId, i, 1 )
{
assert( Vec_IntEntry(vMap, NameId) != -1 );
Vec_IntPush( vTemp, Vec_IntEntry(vMap, NameId) );
}
Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId, CBA_OBJ_NODE );
Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, Cba_ObjFuncId(pNtk, iObj) );
Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, Cba_ManHandleArray(pNew, vTemp) );
Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, Vec_IntEntry(vFanins, 0) );
}
else if ( Type == CBA_OBJ_BOX )
{
ObjId = Vec_IntEntry( vBoxes, nBoxes++ );
pNtkBox = Cba_ObjModel( pNtk, iObj );
Vec_IntFill( vTemp, Cba_NtkPiNum(pNtkBox), -1 );
Vec_IntForEachEntry( vFanins, Index, i )
{
i++; NameId = Vec_IntEntry( vFanins, i );
assert( Vec_IntEntry(vMap, NameId) != -1 );
if ( Index < Cba_NtkPiNum(pNtkBox) )
Vec_IntWriteEntry( vTemp, Index, Vec_IntEntry(vMap, NameId) );
else
Vec_IntWriteEntry( &pNtkNew->vNameIds, Vec_IntEntry(vMap, NameId), NameId );
}
Vec_IntForEachEntry( vTemp, Index, i )
assert( Index >= 0 );
// craete box
Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId, CBA_OBJ_BOX );
Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, Cba_ManNtkId(pNew, Cba_NtkName(pNtkBox)) );
Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, Cba_ManHandleArray(pNew, vTemp) );
// create box outputs
for ( i = 1; i <= Cba_NtkPoNum(pNtkBox); i++ )
{
Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId + i, CBA_OBJ_PIN );
Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId + i, -1 );
Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId + i, Cba_ManHandleBuffer(pNew, ObjId) );
}
}
}
assert( nBoxes == Vec_IntSize(vBoxes) );
Cba_NtkForEachPo( pNtk, NameId, i )
{
ObjId = nObjCount + i;
FaninId = Vec_IntEntry( vMap, NameId );
assert( FaninId != -1 );
Vec_IntWriteEntry( &pNtkNew->vOutputs, i, ObjId );
Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId, CBA_OBJ_PO );
Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, -1 );
Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, Cba_ManHandleBuffer(pNew, FaninId) );
// remove NameId from the driver and assign it to the output
Vec_IntWriteEntry( &pNtkNew->vNameIds, FaninId, -1 );
Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, NameId );
}
// clean map
Cba_NtkForEachPi( pNtk, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 );
Cba_NtkForEachObjType( pNtk, Type, iObj )
{
vFanins = Cba_ObjFaninVec( pNtk, iObj );
if ( Type == CBA_OBJ_NODE )
{
Vec_IntForEachEntry( vFanins, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 );
}
else if ( Type == CBA_OBJ_BOX )
{
Vec_IntForEachEntry( vFanins, Index, i )
Vec_IntWriteEntry( vMap, Vec_IntEntry(vFanins, ++i), -1 );
}
}
Cba_NtkForEachPo( pNtk, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 );
return pNtkNew;
} }
Int_Des_t * Ptr_ManConvert( Vec_Ptr_t * vDesPtr ) Cba_Man_t * Cba_ManBuild( Cba_Man_t * p )
{ {
Vec_Ptr_t * vNtk; int i; Cba_Man_t * pNew = Cba_ManAlloc( Cba_ManName(p) );
char * pName = (char *)Vec_PtrEntry(vDesPtr, 0); Vec_Int_t * vMap = Vec_IntStartFull( Abc_NamObjNumMax(p->pNames) + 1 );
Vec_Ptr_t * vDes = Ptr_ManDumpToInt( vDesPtr ); Vec_Int_t * vBoxes = Vec_IntAlloc( 1000 );
Abc_Nam_t * pNames = (Abc_Nam_t *)Vec_PtrEntry(vDes, 0); Vec_Int_t * vTemp = Vec_IntAlloc( 1000 );
Vec_Wrd_t * vMap = Vec_WrdStartFull( Abc_NamObjNumMax(pNames) + 1 ); Cba_Ntk_t * pNtk; int i;
Vec_Int_t * vMap2 = Vec_IntStartFull( Abc_NamObjNumMax(pNames) + 1 ); Cba_ManForEachNtk( p, pNtk, i )
Int_Des_t * pDes = Int_DesAlloc( pName, pNames, Vec_PtrSize(vDes)-1 ); Abc_NamStrFindOrAdd( p->pModels, Cba_NtkName(pNtk), NULL );
Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) assert( Abc_NamObjNumMax(p->pModels) == Cba_ManNtkNum(p) + 1 );
Vec_PtrPush( &pDes->vModels, Ptr_ManConvertNtkInter(pDes, vNtk, i) ); Cba_RemapBoxes( pNtk, vMap );
Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 ) Cba_ManForEachNtk( p, pNtk, i )
Ptr_ManConvertNtk( Int_DesNtk(pDes, i), vNtk, vMap, vMap2 ); Cba_NtkBuild( p, pNtk, vMap, vBoxes, vTemp );
// Ptr_ManFreeDes( vDes ); Vec_IntFree( vTemp );
Vec_IntFree( vMap2 ); Vec_IntFree( vBoxes );
Vec_WrdFree( vMap ); Vec_IntFree( vMap );
return pDes; return pNew;
} }
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -41,7 +41,27 @@ ABC_NAMESPACE_IMPL_START ...@@ -41,7 +41,27 @@ ABC_NAMESPACE_IMPL_START
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Cba_ManAssignInternNamesNtk( Cba_Ntk_t * p )
{
int i, Type, NameId;
int nDigits = Abc_Base10Log( Cba_NtkObjNum(p) );
Cba_NtkForEachObjType( p, Type, i )
{
if ( Type == CBA_OBJ_NODE || Type == CBA_OBJ_PIN )
{
char Buffer[100];
sprintf( Buffer, "%s%0*d", "_n_", nDigits, i );
NameId = Abc_NamStrFindOrAdd( p->pDesign->pNames, Buffer, NULL );
Vec_IntWriteEntry( &p->vNameIds, i, NameId );
}
}
}
void Cba_ManAssignInternNames( Cba_Man_t * p )
{
Cba_Ntk_t * pNtk; int i;
Cba_ManForEachNtk( p, pNtk, i )
Cba_ManAssignInternNamesNtk( pNtk );
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
......
...@@ -111,38 +111,19 @@ static inline int Cba_PrsErrorPrint( Cba_Prs_t * p ) ...@@ -111,38 +111,19 @@ static inline int Cba_PrsErrorPrint( Cba_Prs_t * p )
return 0; return 0;
} }
// create network
// copy contents to the vector
static inline int Cba_PrsSetupDataInt( Cba_Prs_t * p, Vec_Int_t * vFrom )
{
int h = Vec_SetFetchH( Cba_ManMem(p->pDesign), sizeof(int) * (Vec_IntSize(vFrom) + 1) );
int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p->pDesign), h );
pArray[0] = Vec_IntSize(vFrom);
memcpy( pArray+1, Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
return h;
}
static inline void Cba_PrsSetupVecInt( Cba_Prs_t * p, Vec_Int_t * vTo, Vec_Int_t * vFrom )
{
if ( Vec_IntSize(vFrom) == 0 )
return;
vTo->nSize = vTo->nCap = Vec_IntSize(vFrom);
vTo->pArray = (int *)Vec_SetFetch( Cba_ManMem(p->pDesign), sizeof(int) * Vec_IntSize(vFrom) );
memcpy( Vec_IntArray(vTo), Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
Vec_IntClear( vFrom );
}
static inline Cba_Ntk_t * Cba_PrsAddCurrentModel( Cba_Prs_t * p, int iNameId ) static inline Cba_Ntk_t * Cba_PrsAddCurrentModel( Cba_Prs_t * p, int iNameId )
{ {
Cba_Ntk_t * pNtk = Cba_NtkAlloc( p->pDesign, Abc_NamStr(p->pDesign->pNames, iNameId) ); Cba_Ntk_t * pNtk = Cba_NtkAlloc( p->pDesign, Abc_NamStr(p->pDesign->pNames, iNameId) );
assert( Vec_IntSize(&p->vInputsCur) != 0 || Vec_IntSize(&p->vOutputsCur) != 0 ); assert( Vec_IntSize(&p->vInputsCur) != 0 || Vec_IntSize(&p->vOutputsCur) != 0 );
Cba_PrsSetupVecInt( p, &pNtk->vInouts, &p->vInoutsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vInouts, &p->vInoutsCur );
Cba_PrsSetupVecInt( p, &pNtk->vInputs, &p->vInputsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vInputs, &p->vInputsCur );
Cba_PrsSetupVecInt( p, &pNtk->vOutputs, &p->vOutputsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vOutputs, &p->vOutputsCur );
Cba_PrsSetupVecInt( p, &pNtk->vWires, &p->vWiresCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vWires, &p->vWiresCur );
Cba_PrsSetupVecInt( p, &pNtk->vTypes, &p->vTypesCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vTypes, &p->vTypesCur );
Cba_PrsSetupVecInt( p, &pNtk->vFuncs, &p->vFuncsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vFuncs, &p->vFuncsCur );
Cba_PrsSetupVecInt( p, &pNtk->vInstIds, &p->vInstIdsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vInstIds, &p->vInstIdsCur );
Cba_PrsSetupVecInt( p, &pNtk->vFanins, &p->vFaninsCur ); Cba_ManSetupArray( p->pDesign, &pNtk->vFanins, &p->vFaninsCur );
return pNtk; return pNtk;
} }
......
...@@ -267,7 +267,7 @@ static inline int Cba_PrsReadNode( Cba_Prs_t * p ) ...@@ -267,7 +267,7 @@ static inline int Cba_PrsReadNode( Cba_Prs_t * p )
// save results // save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE ); Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, 1 ); // default const 0 function Vec_IntPush( &p->vFuncsCur, 1 ); // default const 0 function
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 0; return 0;
} }
static inline int Cba_PrsReadBox( Cba_Prs_t * p, int fGate ) static inline int Cba_PrsReadBox( Cba_Prs_t * p, int fGate )
...@@ -278,7 +278,7 @@ static inline int Cba_PrsReadBox( Cba_Prs_t * p, int fGate ) ...@@ -278,7 +278,7 @@ static inline int Cba_PrsReadBox( Cba_Prs_t * p, int fGate )
// save results // save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_BOX ); Vec_IntPush( &p->vTypesCur, CBA_PRS_BOX );
Vec_IntPush( &p->vFuncsCur, iToken ); Vec_IntPush( &p->vFuncsCur, iToken );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 0; return 0;
} }
static inline int Cba_PrsReadLatch( Cba_Prs_t * p ) static inline int Cba_PrsReadLatch( Cba_Prs_t * p )
...@@ -301,7 +301,7 @@ static inline int Cba_PrsReadLatch( Cba_Prs_t * p ) ...@@ -301,7 +301,7 @@ static inline int Cba_PrsReadLatch( Cba_Prs_t * p )
// save results // save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_LATCH ); Vec_IntPush( &p->vTypesCur, CBA_PRS_LATCH );
Vec_IntPush( &p->vFuncsCur, iToken ); Vec_IntPush( &p->vFuncsCur, iToken );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 0; return 0;
} }
static inline int Cba_PrsReadShort( Cba_Prs_t * p ) static inline int Cba_PrsReadShort( Cba_Prs_t * p )
...@@ -318,7 +318,7 @@ static inline int Cba_PrsReadShort( Cba_Prs_t * p ) ...@@ -318,7 +318,7 @@ static inline int Cba_PrsReadShort( Cba_Prs_t * p )
// save results // save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE ); Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, 2 ); // default buffer function Vec_IntPush( &p->vFuncsCur, 2 ); // default buffer function
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 0; return 0;
} }
static inline int Cba_PrsReadModel( Cba_Prs_t * p ) static inline int Cba_PrsReadModel( Cba_Prs_t * p )
......
...@@ -370,7 +370,7 @@ static inline int Cba_PrsReadConcat( Cba_Prs_t * p, Vec_Int_t * vTemp2 ) ...@@ -370,7 +370,7 @@ static inline int Cba_PrsReadConcat( Cba_Prs_t * p, Vec_Int_t * vTemp2 )
Vec_IntPush( &p->vTypesCur, CBA_PRS_CONCAT ); Vec_IntPush( &p->vTypesCur, CBA_PRS_CONCAT );
Vec_IntPush( &p->vFuncsCur, 0 ); Vec_IntPush( &p->vFuncsCur, 0 );
Vec_IntPush( &p->vInstIdsCur, 0 ); Vec_IntPush( &p->vInstIdsCur, 0 );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, vTemp2) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, vTemp2) );
return Vec_IntSize(&p->vFaninsCur); return Vec_IntSize(&p->vFaninsCur);
} }
static inline int Cba_PrsReadSignalOrConcat( Cba_Prs_t * p, int * pName, int * pRange ) static inline int Cba_PrsReadSignalOrConcat( Cba_Prs_t * p, int * pName, int * pRange )
...@@ -500,7 +500,7 @@ static inline int Cba_PrsReadAssign( Cba_Prs_t * p ) ...@@ -500,7 +500,7 @@ static inline int Cba_PrsReadAssign( Cba_Prs_t * p )
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE ); Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, fCompl ? CBA_NODE_INV : CBA_NODE_BUF ); Vec_IntPush( &p->vFuncsCur, fCompl ? CBA_NODE_INV : CBA_NODE_BUF );
Vec_IntPush( &p->vInstIdsCur, 0 ); Vec_IntPush( &p->vInstIdsCur, 0 );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 1; return 1;
} }
if ( Cba_PrsIsChar(p, '&') ) if ( Cba_PrsIsChar(p, '&') )
...@@ -535,7 +535,7 @@ static inline int Cba_PrsReadAssign( Cba_Prs_t * p ) ...@@ -535,7 +535,7 @@ static inline int Cba_PrsReadAssign( Cba_Prs_t * p )
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE ); Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, Oper ); Vec_IntPush( &p->vFuncsCur, Oper );
Vec_IntPush( &p->vInstIdsCur, 0 ); Vec_IntPush( &p->vInstIdsCur, 0 );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 1; return 1;
} }
static inline int Cba_PrsReadInstance( Cba_Prs_t * p, int Func ) static inline int Cba_PrsReadInstance( Cba_Prs_t * p, int Func )
...@@ -565,7 +565,7 @@ static inline int Cba_PrsReadInstance( Cba_Prs_t * p, int Func ) ...@@ -565,7 +565,7 @@ static inline int Cba_PrsReadInstance( Cba_Prs_t * p, int Func )
Vec_IntPush( &p->vTypesCur, Type ); Vec_IntPush( &p->vTypesCur, Type );
Vec_IntPush( &p->vFuncsCur, Func ); Vec_IntPush( &p->vFuncsCur, Func );
Vec_IntPush( &p->vInstIdsCur, InstId ); Vec_IntPush( &p->vInstIdsCur, InstId );
Vec_IntPush( &p->vFaninsCur, Cba_PrsSetupDataInt(p, &p->vTemp) ); Vec_IntPush( &p->vFaninsCur, Cba_ManHandleArray(p->pDesign, &p->vTemp) );
return 1; return 1;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
***********************************************************************/ ***********************************************************************/
#include "cba.h" #include "cba.h"
#include "cbaPrs.h"
#include "base/abc/abc.h" #include "base/abc/abc.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -144,18 +145,18 @@ Ptr_ObjType_t Ptr_HopToType( Abc_Obj_t * pObj ) ...@@ -144,18 +145,18 @@ Ptr_ObjType_t Ptr_HopToType( Abc_Obj_t * pObj )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
static inline char * Ptr_ObjName( Abc_Obj_t * pObj ) char * Ptr_AbcObjName( Abc_Obj_t * pObj )
{ {
if ( Abc_ObjIsNet(pObj) || Abc_ObjIsBox(pObj) ) if ( Abc_ObjIsNet(pObj) || Abc_ObjIsBox(pObj) )
return Abc_ObjName(pObj); return Abc_ObjName(pObj);
if ( Abc_ObjIsCi(pObj) || Abc_ObjIsNode(pObj) ) if ( Abc_ObjIsCi(pObj) || Abc_ObjIsNode(pObj) )
return Ptr_ObjName(Abc_ObjFanout0(pObj)); return Ptr_AbcObjName(Abc_ObjFanout0(pObj));
if ( Abc_ObjIsCo(pObj) ) if ( Abc_ObjIsCo(pObj) )
return Ptr_ObjName(Abc_ObjFanin0(pObj)); return Ptr_AbcObjName(Abc_ObjFanin0(pObj));
assert( 0 ); assert( 0 );
return NULL; return NULL;
} }
static int Ptr_ManCheckArray( Vec_Ptr_t * vArray ) static int Ptr_CheckArray( Vec_Ptr_t * vArray )
{ {
if ( Vec_PtrSize(vArray) == 0 ) if ( Vec_PtrSize(vArray) == 0 )
return 1; return 1;
...@@ -164,97 +165,97 @@ static int Ptr_ManCheckArray( Vec_Ptr_t * vArray ) ...@@ -164,97 +165,97 @@ static int Ptr_ManCheckArray( Vec_Ptr_t * vArray )
assert( 0 ); assert( 0 );
return 0; return 0;
} }
Vec_Ptr_t * Ptr_ManDeriveNode( Abc_Obj_t * pObj ) Vec_Ptr_t * Ptr_AbcDeriveNode( Abc_Obj_t * pObj )
{ {
Abc_Obj_t * pFanin; int i; Abc_Obj_t * pFanin; int i;
Vec_Ptr_t * vNode = Vec_PtrAlloc( 2 + Abc_ObjFaninNum(pObj) ); Vec_Ptr_t * vNode = Vec_PtrAlloc( 2 + Abc_ObjFaninNum(pObj) );
assert( Abc_ObjIsNode(pObj) ); assert( Abc_ObjIsNode(pObj) );
Vec_PtrPush( vNode, Ptr_ObjName(pObj) ); Vec_PtrPush( vNode, Ptr_AbcObjName(pObj) );
Vec_PtrPush( vNode, Abc_Int2Ptr(Ptr_HopToType(pObj)) ); Vec_PtrPush( vNode, Abc_Int2Ptr(Ptr_HopToType(pObj)) );
Abc_ObjForEachFanin( pObj, pFanin, i ) Abc_ObjForEachFanin( pObj, pFanin, i )
Vec_PtrPush( vNode, Ptr_ObjName(pFanin) ); Vec_PtrPush( vNode, Ptr_AbcObjName(pFanin) );
assert( Ptr_ManCheckArray(vNode) ); assert( Ptr_CheckArray(vNode) );
return vNode; return vNode;
} }
Vec_Ptr_t * Ptr_ManDeriveNodes( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveNodes( Abc_Ntk_t * pNtk )
{ {
Abc_Obj_t * pObj; int i; Abc_Obj_t * pObj; int i;
Vec_Ptr_t * vNodes = Vec_PtrAlloc( Abc_NtkNodeNum(pNtk) ); Vec_Ptr_t * vNodes = Vec_PtrAlloc( Abc_NtkNodeNum(pNtk) );
Abc_NtkForEachNode( pNtk, pObj, i ) Abc_NtkForEachNode( pNtk, pObj, i )
Vec_PtrPush( vNodes, Ptr_ManDeriveNode(pObj) ); Vec_PtrPush( vNodes, Ptr_AbcDeriveNode(pObj) );
assert( Ptr_ManCheckArray(vNodes) ); assert( Ptr_CheckArray(vNodes) );
return vNodes; return vNodes;
} }
Vec_Ptr_t * Ptr_ManDeriveBox( Abc_Obj_t * pObj ) Vec_Ptr_t * Ptr_AbcDeriveBox( Abc_Obj_t * pObj )
{ {
Abc_Obj_t * pNext; int i; Abc_Obj_t * pNext; int i;
Abc_Ntk_t * pModel = Abc_ObjModel(pObj); Abc_Ntk_t * pModel = Abc_ObjModel(pObj);
Vec_Ptr_t * vBox = Vec_PtrAlloc( 2 + 2 * Abc_ObjFaninNum(pObj) + 2 * Abc_ObjFanoutNum(pObj) ); Vec_Ptr_t * vBox = Vec_PtrAlloc( 2 + 2 * Abc_ObjFaninNum(pObj) + 2 * Abc_ObjFanoutNum(pObj) );
assert( Abc_ObjIsBox(pObj) ); assert( Abc_ObjIsBox(pObj) );
Vec_PtrPush( vBox, Abc_NtkName(pModel) ); Vec_PtrPush( vBox, Abc_NtkName(pModel) );
Vec_PtrPush( vBox, Ptr_ObjName(pObj) ); Vec_PtrPush( vBox, Ptr_AbcObjName(pObj) );
Abc_ObjForEachFanin( pObj, pNext, i ) Abc_ObjForEachFanin( pObj, pNext, i )
{ {
Vec_PtrPush( vBox, Ptr_ObjName(Abc_NtkPi(pModel, i)) ); Vec_PtrPush( vBox, Ptr_AbcObjName(Abc_NtkPi(pModel, i)) );
Vec_PtrPush( vBox, Ptr_ObjName(pNext) ); Vec_PtrPush( vBox, Ptr_AbcObjName(pNext) );
} }
Abc_ObjForEachFanout( pObj, pNext, i ) Abc_ObjForEachFanout( pObj, pNext, i )
{ {
Vec_PtrPush( vBox, Ptr_ObjName(Abc_NtkPo(pModel, i)) ); Vec_PtrPush( vBox, Ptr_AbcObjName(Abc_NtkPo(pModel, i)) );
Vec_PtrPush( vBox, Ptr_ObjName(pNext) ); Vec_PtrPush( vBox, Ptr_AbcObjName(pNext) );
} }
assert( Ptr_ManCheckArray(vBox) ); assert( Ptr_CheckArray(vBox) );
return vBox; return vBox;
} }
Vec_Ptr_t * Ptr_ManDeriveBoxes( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveBoxes( Abc_Ntk_t * pNtk )
{ {
Abc_Obj_t * pObj; int i; Abc_Obj_t * pObj; int i;
Vec_Ptr_t * vBoxes = Vec_PtrAlloc( Abc_NtkBoxNum(pNtk) ); Vec_Ptr_t * vBoxes = Vec_PtrAlloc( Abc_NtkBoxNum(pNtk) );
Abc_NtkForEachBox( pNtk, pObj, i ) Abc_NtkForEachBox( pNtk, pObj, i )
Vec_PtrPush( vBoxes, Ptr_ManDeriveBox(pObj) ); Vec_PtrPush( vBoxes, Ptr_AbcDeriveBox(pObj) );
assert( Ptr_ManCheckArray(vBoxes) ); assert( Ptr_CheckArray(vBoxes) );
return vBoxes; return vBoxes;
} }
Vec_Ptr_t * Ptr_ManDeriveInputs( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveInputs( Abc_Ntk_t * pNtk )
{ {
Abc_Obj_t * pObj; int i; Abc_Obj_t * pObj; int i;
Vec_Ptr_t * vSigs = Vec_PtrAlloc( Abc_NtkPiNum(pNtk) ); Vec_Ptr_t * vSigs = Vec_PtrAlloc( Abc_NtkPiNum(pNtk) );
Abc_NtkForEachPi( pNtk, pObj, i ) Abc_NtkForEachPi( pNtk, pObj, i )
Vec_PtrPush( vSigs, Ptr_ObjName(pObj) ); Vec_PtrPush( vSigs, Ptr_AbcObjName(pObj) );
assert( Ptr_ManCheckArray(vSigs) ); assert( Ptr_CheckArray(vSigs) );
return vSigs; return vSigs;
} }
Vec_Ptr_t * Ptr_ManDeriveOutputs( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveOutputs( Abc_Ntk_t * pNtk )
{ {
Abc_Obj_t * pObj; int i; Abc_Obj_t * pObj; int i;
Vec_Ptr_t * vSigs = Vec_PtrAlloc( Abc_NtkPoNum(pNtk) ); Vec_Ptr_t * vSigs = Vec_PtrAlloc( Abc_NtkPoNum(pNtk) );
Abc_NtkForEachPo( pNtk, pObj, i ) Abc_NtkForEachPo( pNtk, pObj, i )
Vec_PtrPush( vSigs, Ptr_ObjName(pObj) ); Vec_PtrPush( vSigs, Ptr_AbcObjName(pObj) );
assert( Ptr_ManCheckArray(vSigs) ); assert( Ptr_CheckArray(vSigs) );
return vSigs; return vSigs;
} }
Vec_Ptr_t * Ptr_ManDeriveNtk( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveNtk( Abc_Ntk_t * pNtk )
{ {
Vec_Ptr_t * vNtk = Vec_PtrAlloc( 5 ); Vec_Ptr_t * vNtk = Vec_PtrAlloc( 5 );
Vec_PtrPush( vNtk, Abc_NtkName(pNtk) ); Vec_PtrPush( vNtk, Abc_NtkName(pNtk) );
Vec_PtrPush( vNtk, Ptr_ManDeriveInputs(pNtk) ); Vec_PtrPush( vNtk, Ptr_AbcDeriveInputs(pNtk) );
Vec_PtrPush( vNtk, Ptr_ManDeriveOutputs(pNtk) ); Vec_PtrPush( vNtk, Ptr_AbcDeriveOutputs(pNtk) );
Vec_PtrPush( vNtk, Ptr_ManDeriveNodes(pNtk) ); Vec_PtrPush( vNtk, Ptr_AbcDeriveNodes(pNtk) );
Vec_PtrPush( vNtk, Ptr_ManDeriveBoxes(pNtk) ); Vec_PtrPush( vNtk, Ptr_AbcDeriveBoxes(pNtk) );
assert( Ptr_ManCheckArray(vNtk) ); assert( Ptr_CheckArray(vNtk) );
return vNtk; return vNtk;
} }
Vec_Ptr_t * Ptr_ManDeriveDes( Abc_Ntk_t * pNtk ) Vec_Ptr_t * Ptr_AbcDeriveDes( Abc_Ntk_t * pNtk )
{ {
Vec_Ptr_t * vDes; Vec_Ptr_t * vDes;
Abc_Ntk_t * pTemp; int i; Abc_Ntk_t * pTemp; int i;
vDes = Vec_PtrAlloc( 1 + Vec_PtrSize(pNtk->pDesign->vModules) ); vDes = Vec_PtrAlloc( 1 + Vec_PtrSize(pNtk->pDesign->vModules) );
Vec_PtrPush( vDes, pNtk->pDesign->pName ); Vec_PtrPush( vDes, pNtk->pDesign->pName );
Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pTemp, i ) Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pTemp, i )
Vec_PtrPush( vDes, Ptr_ManDeriveNtk(pTemp) ); Vec_PtrPush( vDes, Ptr_AbcDeriveNtk(pTemp) );
assert( Ptr_ManCheckArray(vDes) ); assert( Ptr_CheckArray(vDes) );
return vDes; return vDes;
} }
...@@ -500,7 +501,7 @@ void Ptr_ManExperiment( Abc_Ntk_t * pNtk ) ...@@ -500,7 +501,7 @@ void Ptr_ManExperiment( Abc_Ntk_t * pNtk )
{ {
abctime clk = Abc_Clock(); abctime clk = Abc_Clock();
char * pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out.blif"); char * pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out.blif");
Vec_Ptr_t * vDes = Ptr_ManDeriveDes( pNtk ); Vec_Ptr_t * vDes = Ptr_AbcDeriveDes( pNtk );
printf( "Converting to Ptr: Memory = %6.3f MB ", 1.0*Ptr_ManMemDes(vDes)/(1<<20) ); printf( "Converting to Ptr: Memory = %6.3f MB ", 1.0*Ptr_ManMemDes(vDes)/(1<<20) );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
Ptr_ManDumpBlif( pFileName, vDes ); Ptr_ManDumpBlif( pFileName, vDes );
...@@ -511,6 +512,238 @@ void Ptr_ManExperiment( Abc_Ntk_t * pNtk ) ...@@ -511,6 +512,238 @@ void Ptr_ManExperiment( Abc_Ntk_t * pNtk )
/**Function*************************************************************
Synopsis [Dumping hierarchical Cba_Ntk_t in Ptr form.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Ptr_t * Ptr_CbaDeriveNode( Cba_Ntk_t * pNtk, int iObj )
{
Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj );
Vec_Ptr_t * vNode = Vec_PtrAlloc( 2 + Vec_IntSize(vFanins) );
int i, iFanin;
assert( Cba_ObjIsNode(pNtk, iObj) );
Vec_PtrPush( vNode, Cba_ObjNameStr(pNtk, iObj) );
if ( Abc_NamObjNumMax(pNtk->pDesign->pFuncs) > 1 )
Vec_PtrPush( vNode, Cba_NtkFuncStr( pNtk, Cba_ObjFuncId(pNtk, iObj) ) );
else
Vec_PtrPush( vNode, Abc_Int2Ptr(Cba_ObjFuncId(pNtk, iObj)) );
Vec_IntForEachEntry( vFanins, iFanin, i )
Vec_PtrPush( vNode, Cba_ObjNameStr(pNtk, iFanin) );
assert( Ptr_CheckArray(vNode) );
return vNode;
}
Vec_Ptr_t * Ptr_CbaDeriveNodes( Cba_Ntk_t * pNtk )
{
int Type, iObj;
Vec_Ptr_t * vNodes = Vec_PtrAlloc( Cba_NtkNodeNum(pNtk) );
Cba_NtkForEachObjType( pNtk, Type, iObj )
if ( Type == CBA_PRS_NODE )
Vec_PtrPush( vNodes, Ptr_CbaDeriveNode(pNtk, iObj) );
assert( Ptr_CheckArray(vNodes) );
return vNodes;
}
Vec_Ptr_t * Ptr_CbaDeriveBox( Cba_Ntk_t * pNtk, int iObj )
{
int i, iTerm;
Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj );
Cba_Ntk_t * pModel = Cba_ObjModel( pNtk, iObj );
Vec_Ptr_t * vBox = Vec_PtrAlloc( 2 + Cba_NtkPiNum(pModel) + Cba_NtkPoNum(pModel) );
assert( Cba_ObjIsBox(pNtk, iObj) );
assert( Cba_NtkPiNum(pModel) == Vec_IntSize(vFanins) );
Vec_PtrPush( vBox, Cba_NtkName(pModel) );
Vec_PtrPush( vBox, Vec_IntSize(&pNtk->vInstIds) ? Cba_ObjInstStr(pNtk, iObj) : NULL );
Cba_NtkForEachPi( pModel, iTerm, i )
{
Vec_PtrPush( vBox, Cba_ObjNameStr(pModel, iTerm) );
Vec_PtrPush( vBox, Cba_ObjNameStr(pNtk, Vec_IntEntry(vFanins, i)) );
}
Cba_NtkForEachPo( pModel, iTerm, i )
{
Vec_PtrPush( vBox, Cba_ObjNameStr(pModel, iTerm) );
Vec_PtrPush( vBox, Cba_ObjNameStr(pNtk, iObj+1+i) );
}
assert( Ptr_CheckArray(vBox) );
return vBox;
}
Vec_Ptr_t * Ptr_CbaDeriveBoxes( Cba_Ntk_t * pNtk )
{
int Type, iObj;
Vec_Ptr_t * vBoxes = Vec_PtrAlloc( Cba_NtkBoxNum(pNtk) );
Cba_NtkForEachObjType( pNtk, Type, iObj )
if ( Type == CBA_PRS_BOX )
Vec_PtrPush( vBoxes, Ptr_CbaDeriveBox(pNtk, iObj) );
assert( Ptr_CheckArray(vBoxes) );
return vBoxes;
}
Vec_Ptr_t * Ptr_CbaDeriveInputs( Cba_Ntk_t * pNtk )
{
int i, iObj;
Vec_Ptr_t * vSigs = Vec_PtrAlloc( Cba_NtkPiNum(pNtk) );
Cba_NtkForEachPi( pNtk, iObj, i )
Vec_PtrPush( vSigs, Cba_ObjNameStr(pNtk, iObj) );
assert( Ptr_CheckArray(vSigs) );
return vSigs;
}
Vec_Ptr_t * Ptr_CbaDeriveOutputs( Cba_Ntk_t * pNtk )
{
int i, iObj;
Vec_Ptr_t * vSigs = Vec_PtrAlloc( Cba_NtkPoNum(pNtk) );
Cba_NtkForEachPo( pNtk, iObj, i )
Vec_PtrPush( vSigs, Cba_ObjNameStr(pNtk, iObj) );
assert( Ptr_CheckArray(vSigs) );
return vSigs;
}
Vec_Ptr_t * Ptr_CbaDeriveNtk( Cba_Ntk_t * pNtk )
{
Vec_Ptr_t * vNtk = Vec_PtrAlloc( 5 );
Vec_PtrPush( vNtk, Cba_NtkName(pNtk) );
Vec_PtrPush( vNtk, Ptr_CbaDeriveInputs(pNtk) );
Vec_PtrPush( vNtk, Ptr_CbaDeriveOutputs(pNtk) );
Vec_PtrPush( vNtk, Ptr_CbaDeriveNodes(pNtk) );
Vec_PtrPush( vNtk, Ptr_CbaDeriveBoxes(pNtk) );
assert( Ptr_CheckArray(vNtk) );
return vNtk;
}
Vec_Ptr_t * Ptr_CbaDeriveDes( Cba_Man_t * p )
{
Vec_Ptr_t * vDes;
Cba_Ntk_t * pTemp; int i;
vDes = Vec_PtrAlloc( 1 + Cba_ManNtkNum(p) );
Vec_PtrPush( vDes, p->pName );
Cba_ManForEachNtk( p, pTemp, i )
Vec_PtrPush( vDes, Ptr_CbaDeriveNtk(pTemp) );
assert( Ptr_CheckArray(vDes) );
return vDes;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Cba_PrsReadList( Cba_Man_t * p, Vec_Ptr_t * vNames, Vec_Int_t * vList, int nSkip, int nSkip2 )
{
char * pName; int i;
Vec_IntClear( vList );
Vec_PtrForEachEntry( char *, vNames, pName, i )
if ( i != nSkip && i != nSkip2 )
Vec_IntPush( vList, Abc_NamStrFindOrAdd(p->pNames, pName, NULL) );
return vList;
}
void Cba_PrsReadNodes( Cba_Man_t * p, Vec_Ptr_t * vNodes, Vec_Int_t * vTypesCur, Vec_Int_t * vFuncsCur, Vec_Int_t * vInstIdsCur, Vec_Int_t * vFaninsCur, Vec_Int_t * vList )
{
Vec_Ptr_t * vNode; int i;
Vec_PtrForEachEntry( Vec_Ptr_t *, vNodes, vNode, i )
{
Vec_IntPush( vTypesCur, CBA_PRS_NODE );
Vec_IntPush( vFuncsCur, (Ptr_ObjType_t)Abc_Ptr2Int(Vec_PtrEntry(vNode, 1)) );
Vec_IntPush( vInstIdsCur, 0 );
Vec_IntPush( vFaninsCur, Cba_ManHandleArray(p, Cba_PrsReadList(p, vNode, vList, 1, -1)) );
}
}
void Cba_PrsReadBoxes( Cba_Man_t * p, Vec_Ptr_t * vBoxes, Vec_Int_t * vTypesCur, Vec_Int_t * vFuncsCur, Vec_Int_t * vInstIdsCur, Vec_Int_t * vFaninsCur, Vec_Int_t * vList )
{
Vec_Ptr_t * vBox; int i;
Vec_PtrForEachEntry( Vec_Ptr_t *, vBoxes, vBox, i )
{
Vec_IntPush( vTypesCur, CBA_PRS_BOX );
Vec_IntPush( vFuncsCur, Abc_NamStrFindOrAdd(p->pNames, Vec_PtrEntry(vBox, 0), NULL) );
Vec_IntPush( vInstIdsCur, Abc_NamStrFindOrAdd(p->pNames, Vec_PtrEntry(vBox, 1), NULL) );
Vec_IntPush( vFaninsCur, Cba_ManHandleArray(p, Cba_PrsReadList(p, vBox, vList, 0, 1)) );
}
}
void Cba_PrsReadModule( Cba_Man_t * p, Vec_Ptr_t * vNtk )
{
Vec_Int_t * vInputsCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vOutputsCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vTypesCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vFuncsCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vInstIdsCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vFaninsCur = Vec_IntAlloc( 1000 );
Vec_Int_t * vList = Vec_IntAlloc( 1000 );
Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, (char *)Vec_PtrEntry(vNtk, 0) );
Cba_PrsReadList( p, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), vInputsCur, -1, -1 );
Cba_PrsReadList( p, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), vOutputsCur, -1, -1 );
Cba_PrsReadNodes( p, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3), vTypesCur, vFuncsCur, vInstIdsCur, vFaninsCur, vList );
Cba_PrsReadBoxes( p, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4), vTypesCur, vFuncsCur, vInstIdsCur, vFaninsCur, vList );
Cba_ManSetupArray( p, &pNtk->vInputs, vInputsCur );
Cba_ManSetupArray( p, &pNtk->vOutputs, vOutputsCur );
Cba_ManSetupArray( p, &pNtk->vTypes, vTypesCur );
Cba_ManSetupArray( p, &pNtk->vFuncs, vFuncsCur );
Cba_ManSetupArray( p, &pNtk->vInstIds, vInstIdsCur );
Cba_ManSetupArray( p, &pNtk->vFanins, vFaninsCur );
Vec_IntFree( vInputsCur );
Vec_IntFree( vOutputsCur );
Vec_IntFree( vTypesCur );
Vec_IntFree( vFuncsCur );
Vec_IntFree( vInstIdsCur );
Vec_IntFree( vFaninsCur );
Vec_IntFree( vList );
}
Cba_Man_t * Cba_PrsReadDes( Vec_Ptr_t * vDes )
{
Vec_Ptr_t * vNtk; int i;
Cba_Man_t * p = Cba_ManAlloc( (char *)Vec_PtrEntry(vDes, 0) );
Vec_PtrForEachEntryStart( Vec_Ptr_t *, vDes, vNtk, i, 1 )
Cba_PrsReadModule( p, vNtk );
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cba_ManReadDesExperiment( Abc_Ntk_t * pNtk )
{
abctime clk = Abc_Clock();
char * pFileName1 = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out1.blif");
char * pFileName2 = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out2.blif");
Cba_Man_t * p;
Vec_Ptr_t * vDes = Ptr_AbcDeriveDes( pNtk );
printf( "Converting to Ptr: Memory = %6.3f MB ", 1.0*Ptr_ManMemDes(vDes)/(1<<20) );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
Ptr_ManDumpBlif( pFileName1, vDes );
printf( "Finished writing output file \"%s\". ", pFileName1 );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
p = Cba_PrsReadDes( vDes );
Ptr_ManFreeDes( vDes );
// Abc_NamPrint( p->pDesign->pNames );
Cba_PrsWriteBlif( pFileName2, p );
Cba_ManFree( p );
printf( "Finished writing output file \"%s\". ", pFileName2 );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -121,7 +121,7 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes ) ...@@ -121,7 +121,7 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes )
/**Function************************************************************* /**Function*************************************************************
Synopsis [] Synopsis [Write elaborated design.]
Description [] Description []
...@@ -130,6 +130,87 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes ) ...@@ -130,6 +130,87 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Cba_ManWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, int iObj )
{
int iFanin, i;
Vec_IntForEachEntry( vFanins, iFanin, i )
fprintf( pFile, " %s", Cba_ObjNameStr(p, iFanin) );
if ( iObj >= 0 )
fprintf( pFile, " %s", Cba_ObjNameStr(p, iObj) );
fprintf( pFile, "\n" );
}
void Cba_ManWriteBlifArray2( FILE * pFile, Cba_Ntk_t * p, int iObj )
{
int iTerm, i;
Vec_Int_t * vFanins = Cba_ObjFaninVec( p, iObj );
Cba_Ntk_t * pModel = Cba_ObjModel( p, iObj );
Cba_NtkForEachPi( pModel, iTerm, i )
fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, Vec_IntEntry(vFanins, i)) );
Cba_NtkForEachPo( pModel, iTerm, i )
fprintf( pFile, " %s=%s", Cba_ObjNameStr(pModel, iTerm), Cba_ObjNameStr(p, iObj + 1 + i) );
fprintf( pFile, "\n" );
}
void Cba_ManWriteBlifLines( FILE * pFile, Cba_Ntk_t * p )
{
int Type, i;
Cba_NtkForEachObjType( p, Type, i )
{
if ( Type == CBA_OBJ_NODE ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".names" );
Cba_ManWriteBlifArray( pFile, p, Cba_ObjFaninVec(p, i), i );
fprintf( pFile, "%s", Cba_ObjFuncStr(p, i) );
}
else if ( Type == CBA_OBJ_BOX ) // .names/assign/box2 (no formal/actual binding)
{
fprintf( pFile, ".subckt" );
fprintf( pFile, " %s", Cba_ObjFuncStr(p, i) );
Cba_ManWriteBlifArray2( pFile, p, i );
}
else if ( Type == CBA_OBJ_LATCH ) // .names/assign/box2 (no formal/actual binding)
{
Vec_Int_t * vFanins = Cba_ObjFaninVec(p, i);
fprintf( pFile, ".latch" );
fprintf( pFile, " %s", Cba_ObjNameStr(p, Vec_IntEntry(vFanins, 1)) );
fprintf( pFile, " %s", Cba_ObjNameStr(p, Vec_IntEntry(vFanins, 0)) );
fprintf( pFile, " %c\n", '0' + Cba_ObjFuncId(p, i) );
}
}
}
void Cba_ManWriteBlifNtk( FILE * pFile, Cba_Ntk_t * p )
{
assert( Vec_IntSize(&p->vTypes) == Cba_NtkObjNum(p) );
assert( Vec_IntSize(&p->vFuncs) == Cba_NtkObjNum(p) );
// write header
fprintf( pFile, ".model %s\n", Cba_NtkName(p) );
if ( Vec_IntSize(&p->vInouts) )
fprintf( pFile, ".inouts" );
if ( Vec_IntSize(&p->vInouts) )
Cba_ManWriteBlifArray( pFile, p, &p->vInouts, -1 );
fprintf( pFile, ".inputs" );
Cba_ManWriteBlifArray( pFile, p, &p->vInputs, -1 );
fprintf( pFile, ".outputs" );
Cba_ManWriteBlifArray( pFile, p, &p->vOutputs, -1 );
// 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;
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", Cba_ManName(p), Extra_TimeStamp() );
Cba_ManForEachNtk( p, pNtk, i )
Cba_ManWriteBlifNtk( pFile, pNtk );
fclose( pFile );
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment