Commit ee72b500 by Alan Mishchenko

Various transformations of Cba_Ntk_t.

parent 26b8116a
......@@ -41,7 +41,27 @@ ABC_NAMESPACE_IMPL_START
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 ///
......
......@@ -111,38 +111,19 @@ static inline int Cba_PrsErrorPrint( Cba_Prs_t * p )
return 0;
}
// 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 );
}
// create network
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) );
assert( Vec_IntSize(&p->vInputsCur) != 0 || Vec_IntSize(&p->vOutputsCur) != 0 );
Cba_PrsSetupVecInt( p, &pNtk->vInouts, &p->vInoutsCur );
Cba_PrsSetupVecInt( p, &pNtk->vInputs, &p->vInputsCur );
Cba_PrsSetupVecInt( p, &pNtk->vOutputs, &p->vOutputsCur );
Cba_PrsSetupVecInt( p, &pNtk->vWires, &p->vWiresCur );
Cba_PrsSetupVecInt( p, &pNtk->vTypes, &p->vTypesCur );
Cba_PrsSetupVecInt( p, &pNtk->vFuncs, &p->vFuncsCur );
Cba_PrsSetupVecInt( p, &pNtk->vInstIds, &p->vInstIdsCur );
Cba_PrsSetupVecInt( p, &pNtk->vFanins, &p->vFaninsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vInouts, &p->vInoutsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vInputs, &p->vInputsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vOutputs, &p->vOutputsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vWires, &p->vWiresCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vTypes, &p->vTypesCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vFuncs, &p->vFuncsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vInstIds, &p->vInstIdsCur );
Cba_ManSetupArray( p->pDesign, &pNtk->vFanins, &p->vFaninsCur );
return pNtk;
}
......
......@@ -267,7 +267,7 @@ static inline int Cba_PrsReadNode( Cba_Prs_t * p )
// save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
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;
}
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
Vec_IntPush( &p->vTypesCur, CBA_PRS_BOX );
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;
}
static inline int Cba_PrsReadLatch( Cba_Prs_t * p )
......@@ -301,7 +301,7 @@ static inline int Cba_PrsReadLatch( Cba_Prs_t * p )
// save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_LATCH );
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;
}
static inline int Cba_PrsReadShort( Cba_Prs_t * p )
......@@ -318,7 +318,7 @@ static inline int Cba_PrsReadShort( Cba_Prs_t * p )
// save results
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
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;
}
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 )
Vec_IntPush( &p->vTypesCur, CBA_PRS_CONCAT );
Vec_IntPush( &p->vFuncsCur, 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);
}
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 )
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, fCompl ? CBA_NODE_INV : CBA_NODE_BUF );
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;
}
if ( Cba_PrsIsChar(p, '&') )
......@@ -535,7 +535,7 @@ static inline int Cba_PrsReadAssign( Cba_Prs_t * p )
Vec_IntPush( &p->vTypesCur, CBA_PRS_NODE );
Vec_IntPush( &p->vFuncsCur, Oper );
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;
}
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->vFuncsCur, Func );
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;
}
......
......@@ -121,7 +121,7 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes )
/**Function*************************************************************
Synopsis []
Synopsis [Write elaborated design.]
Description []
......@@ -130,6 +130,87 @@ void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes )
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