#include "wlc.h"
#include "aig/miniaig/ndr.h"
ABC_NAMESPACE_IMPL_START
int Ndr_TypeNdr2Wlc( int Type )
{
if ( Type == ABC_OPER_CONST ) return WLC_OBJ_CONST; if ( Type == ABC_OPER_BIT_BUF ) return WLC_OBJ_BUF; if ( Type == ABC_OPER_BIT_MUX ) return WLC_OBJ_MUX; if ( Type == ABC_OPER_SHIFT_R ) return WLC_OBJ_SHIFT_R; if ( Type == ABC_OPER_SHIFT_RA ) return WLC_OBJ_SHIFT_RA; if ( Type == ABC_OPER_SHIFT_L ) return WLC_OBJ_SHIFT_L; if ( Type == ABC_OPER_SHIFT_LA ) return WLC_OBJ_SHIFT_LA; if ( Type == ABC_OPER_SHIFT_ROTR ) return WLC_OBJ_ROTATE_R; if ( Type == ABC_OPER_SHIFT_ROTL ) return WLC_OBJ_ROTATE_L; if ( Type == ABC_OPER_BIT_INV ) return WLC_OBJ_BIT_NOT; if ( Type == ABC_OPER_BIT_AND ) return WLC_OBJ_BIT_AND; if ( Type == ABC_OPER_BIT_OR ) return WLC_OBJ_BIT_OR; if ( Type == ABC_OPER_BIT_XOR ) return WLC_OBJ_BIT_XOR; if ( Type == ABC_OPER_BIT_NAND ) return WLC_OBJ_BIT_NAND; if ( Type == ABC_OPER_BIT_NOR ) return WLC_OBJ_BIT_NOR; if ( Type == ABC_OPER_BIT_NXOR ) return WLC_OBJ_BIT_NXOR; if ( Type == ABC_OPER_SLICE ) return WLC_OBJ_BIT_SELECT; if ( Type == ABC_OPER_CONCAT ) return WLC_OBJ_BIT_CONCAT; if ( Type == ABC_OPER_ZEROPAD ) return WLC_OBJ_BIT_ZEROPAD; if ( Type == ABC_OPER_SIGNEXT ) return WLC_OBJ_BIT_SIGNEXT; if ( Type == ABC_OPER_LOGIC_NOT ) return WLC_OBJ_LOGIC_NOT; if ( Type == ABC_OPER_LOGIC_IMPL ) return WLC_OBJ_LOGIC_IMPL; if ( Type == ABC_OPER_LOGIC_AND ) return WLC_OBJ_LOGIC_AND; if ( Type == ABC_OPER_LOGIC_OR ) return WLC_OBJ_LOGIC_OR; if ( Type == ABC_OPER_LOGIC_XOR ) return WLC_OBJ_LOGIC_XOR; if ( Type == ABC_OPER_SEL_NMUX ) return WLC_OBJ_MUX; if ( Type == ABC_OPER_SEL_SEL ) return WLC_OBJ_SEL; if ( Type == ABC_OPER_SEL_DEC ) return WLC_OBJ_DEC; if ( Type == ABC_OPER_COMP_EQU ) return WLC_OBJ_COMP_EQU; if ( Type == ABC_OPER_COMP_NOTEQU ) return WLC_OBJ_COMP_NOTEQU; if ( Type == ABC_OPER_COMP_LESS ) return WLC_OBJ_COMP_LESS; if ( Type == ABC_OPER_COMP_MORE ) return WLC_OBJ_COMP_MORE; if ( Type == ABC_OPER_COMP_LESSEQU ) return WLC_OBJ_COMP_LESSEQU; if ( Type == ABC_OPER_COMP_MOREEQU ) return WLC_OBJ_COMP_MOREEQU; if ( Type == ABC_OPER_RED_AND ) return WLC_OBJ_REDUCT_AND; if ( Type == ABC_OPER_RED_OR ) return WLC_OBJ_REDUCT_OR; if ( Type == ABC_OPER_RED_XOR ) return WLC_OBJ_REDUCT_XOR; if ( Type == ABC_OPER_RED_NAND ) return WLC_OBJ_REDUCT_NAND; if ( Type == ABC_OPER_RED_NOR ) return WLC_OBJ_REDUCT_NOR; if ( Type == ABC_OPER_RED_NXOR ) return WLC_OBJ_REDUCT_NXOR; if ( Type == ABC_OPER_ARI_ADD ) return WLC_OBJ_ARI_ADD; if ( Type == ABC_OPER_ARI_SUB ) return WLC_OBJ_ARI_SUB; if ( Type == ABC_OPER_ARI_MUL ) return WLC_OBJ_ARI_MULTI; if ( Type == ABC_OPER_ARI_DIV ) return WLC_OBJ_ARI_DIVIDE; if ( Type == ABC_OPER_ARI_REM ) return WLC_OBJ_ARI_REM; if ( Type == ABC_OPER_ARI_MOD ) return WLC_OBJ_ARI_MODULUS; if ( Type == ABC_OPER_ARI_POW ) return WLC_OBJ_ARI_POWER; if ( Type == ABC_OPER_ARI_MIN ) return WLC_OBJ_ARI_MINUS; if ( Type == ABC_OPER_ARI_SQRT ) return WLC_OBJ_ARI_SQRT; if ( Type == ABC_OPER_ARI_SQUARE ) return WLC_OBJ_ARI_SQUARE; if ( Type == ABC_OPER_ARI_ADDSUB ) return WLC_OBJ_ARI_ADDSUB; if ( Type == ABC_OPER_ARI_SMUL ) return WLC_OBJ_ARI_MULTI; if ( Type == ABC_OPER_DFF ) return WLC_OBJ_FO; if ( Type == ABC_OPER_DFFRSE ) return WLC_OBJ_FF; if ( Type == ABC_OPER_RAMR ) return WLC_OBJ_READ; if ( Type == ABC_OPER_RAMW ) return WLC_OBJ_WRITE; if ( Type == ABC_OPER_LUT ) return WLC_OBJ_LUT; return -1;
}
int Ndr_TypeWlc2Ndr( int Type )
{
if ( Type == WLC_OBJ_CONST ) return ABC_OPER_CONST; if ( Type == WLC_OBJ_BUF ) return ABC_OPER_BIT_BUF; if ( Type == WLC_OBJ_MUX ) return ABC_OPER_BIT_MUX; if ( Type == WLC_OBJ_SHIFT_R ) return ABC_OPER_SHIFT_R; if ( Type == WLC_OBJ_SHIFT_RA ) return ABC_OPER_SHIFT_RA; if ( Type == WLC_OBJ_SHIFT_L ) return ABC_OPER_SHIFT_L; if ( Type == WLC_OBJ_SHIFT_LA ) return ABC_OPER_SHIFT_LA; if ( Type == WLC_OBJ_ROTATE_R ) return ABC_OPER_SHIFT_ROTR; if ( Type == WLC_OBJ_ROTATE_L ) return ABC_OPER_SHIFT_ROTL; if ( Type == WLC_OBJ_BIT_NOT ) return ABC_OPER_BIT_INV; if ( Type == WLC_OBJ_BIT_AND ) return ABC_OPER_BIT_AND; if ( Type == WLC_OBJ_BIT_OR ) return ABC_OPER_BIT_OR; if ( Type == WLC_OBJ_BIT_XOR ) return ABC_OPER_BIT_XOR; if ( Type == WLC_OBJ_BIT_NAND ) return ABC_OPER_BIT_NAND; if ( Type == WLC_OBJ_BIT_NOR ) return ABC_OPER_BIT_NOR; if ( Type == WLC_OBJ_BIT_NXOR ) return ABC_OPER_BIT_NXOR; if ( Type == WLC_OBJ_BIT_SELECT ) return ABC_OPER_SLICE; if ( Type == WLC_OBJ_BIT_CONCAT ) return ABC_OPER_CONCAT; if ( Type == WLC_OBJ_BIT_ZEROPAD ) return ABC_OPER_ZEROPAD; if ( Type == WLC_OBJ_BIT_SIGNEXT ) return ABC_OPER_SIGNEXT; if ( Type == WLC_OBJ_LOGIC_NOT ) return ABC_OPER_LOGIC_NOT; if ( Type == WLC_OBJ_LOGIC_IMPL ) return ABC_OPER_LOGIC_IMPL; if ( Type == WLC_OBJ_LOGIC_AND ) return ABC_OPER_LOGIC_AND; if ( Type == WLC_OBJ_LOGIC_OR ) return ABC_OPER_LOGIC_OR; if ( Type == WLC_OBJ_LOGIC_XOR ) return ABC_OPER_LOGIC_XOR; if ( Type == WLC_OBJ_SEL ) return ABC_OPER_SEL_SEL; if ( Type == WLC_OBJ_DEC ) return ABC_OPER_SEL_DEC; if ( Type == WLC_OBJ_COMP_EQU ) return ABC_OPER_COMP_EQU; if ( Type == WLC_OBJ_COMP_NOTEQU ) return ABC_OPER_COMP_NOTEQU; if ( Type == WLC_OBJ_COMP_LESS ) return ABC_OPER_COMP_LESS; if ( Type == WLC_OBJ_COMP_MORE ) return ABC_OPER_COMP_MORE; if ( Type == WLC_OBJ_COMP_LESSEQU ) return ABC_OPER_COMP_LESSEQU; if ( Type == WLC_OBJ_COMP_MOREEQU ) return ABC_OPER_COMP_MOREEQU; if ( Type == WLC_OBJ_REDUCT_AND ) return ABC_OPER_RED_AND; if ( Type == WLC_OBJ_REDUCT_OR ) return ABC_OPER_RED_OR; if ( Type == WLC_OBJ_REDUCT_XOR ) return ABC_OPER_RED_XOR; if ( Type == WLC_OBJ_REDUCT_NAND ) return ABC_OPER_RED_NAND; if ( Type == WLC_OBJ_REDUCT_NOR ) return ABC_OPER_RED_NOR; if ( Type == WLC_OBJ_REDUCT_NXOR ) return ABC_OPER_RED_NXOR; if ( Type == WLC_OBJ_ARI_ADD ) return ABC_OPER_ARI_ADD; if ( Type == WLC_OBJ_ARI_SUB ) return ABC_OPER_ARI_SUB; if ( Type == WLC_OBJ_ARI_MULTI ) return ABC_OPER_ARI_MUL; if ( Type == WLC_OBJ_ARI_DIVIDE ) return ABC_OPER_ARI_DIV; if ( Type == WLC_OBJ_ARI_REM ) return ABC_OPER_ARI_REM; if ( Type == WLC_OBJ_ARI_MODULUS ) return ABC_OPER_ARI_MOD; if ( Type == WLC_OBJ_ARI_POWER ) return ABC_OPER_ARI_POW; if ( Type == WLC_OBJ_ARI_MINUS ) return ABC_OPER_ARI_MIN; if ( Type == WLC_OBJ_ARI_SQRT ) return ABC_OPER_ARI_SQRT; if ( Type == WLC_OBJ_ARI_SQUARE ) return ABC_OPER_ARI_SQUARE; if ( Type == WLC_OBJ_ARI_ADDSUB ) return ABC_OPER_ARI_ADDSUB; if ( Type == WLC_OBJ_ARI_MULTI ) return ABC_OPER_ARI_SMUL; if ( Type == WLC_OBJ_FO ) return ABC_OPER_DFFRSE; if ( Type == WLC_OBJ_FF ) return ABC_OPER_DFFRSE; if ( Type == WLC_OBJ_READ ) return ABC_OPER_RAMR; if ( Type == WLC_OBJ_WRITE ) return ABC_OPER_RAMW; if ( Type == WLC_OBJ_LUT ) return ABC_OPER_LUT; return -1;
}
char * Ndr_ObjWriteConstant( unsigned * pBits, int nBits )
{
static char Buffer[10000]; int i, Len;
assert( nBits + 10 < 10000 );
sprintf( Buffer, "%d\'b", nBits );
Len = strlen(Buffer);
for ( i = nBits-1; i >= 0; i-- )
Buffer[Len++] = '0' + Abc_InfoHasBit(pBits, i);
Buffer[Len] = 0;
return Buffer;
}
void * Wlc_NtkToNdr( Wlc_Ntk_t * pNtk )
{
Wlc_Obj_t * pObj;
int i, k, iFanin, iOutId, Type;
void * pDesign = Ndr_Create( 1 );
int ModId = Ndr_AddModule( pDesign, 1 );
Vec_Int_t * vFanins = Vec_IntAlloc( 10 );
Wlc_NtkForEachPi( pNtk, pObj, i )
{
iOutId = Wlc_ObjId(pNtk, pObj);
Ndr_AddObject( pDesign, ModId, ABC_OPER_CI, 0,
pObj->End, pObj->Beg, pObj->Signed,
0, NULL, 1, &iOutId, NULL ); }
Wlc_NtkForEachObj( pNtk, pObj, iOutId )
{
char * pFunction = NULL;
if ( Wlc_ObjIsPi(pObj) || pObj->Type == 0 )
continue;
Vec_IntClear( vFanins );
Wlc_ObjForEachFanin( pObj, iFanin, k )
Vec_IntPush( vFanins, iFanin );
if ( pObj->Type == WLC_OBJ_CONST )
pFunction = Ndr_ObjWriteConstant( (unsigned *)Wlc_ObjFanins(pObj), Wlc_ObjRange(pObj) );
if ( pObj->Type == WLC_OBJ_MUX && Wlc_ObjRange(Wlc_ObjFanin0(pNtk, pObj)) > 1 )
Type = ABC_OPER_SEL_NMUX;
else if ( pObj->Type == WLC_OBJ_FO )
{
Wlc_Obj_t * pFi = Wlc_ObjFo2Fi( pNtk, pObj );
assert( Vec_IntSize(vFanins) == 0 );
Vec_IntPush( vFanins, Wlc_ObjId(pNtk, pFi) );
Vec_IntFillExtra( vFanins, 7, 0 );
Type = ABC_OPER_DFFRSE;
}
else
Type = Ndr_TypeWlc2Ndr(pObj->Type);
assert( Type > 0 );
Ndr_AddObject( pDesign, ModId, Type, 0,
pObj->End, pObj->Beg, pObj->Signed,
Vec_IntSize(vFanins), Vec_IntArray(vFanins), 1, &iOutId, pFunction );
}
Wlc_NtkForEachObj( pNtk, pObj, iOutId )
{
if ( !Wlc_ObjIsPo(pObj) )
continue;
Vec_IntFill( vFanins, 1, iOutId );
Ndr_AddObject( pDesign, ModId, ABC_OPER_CO, 0,
pObj->End, pObj->Beg, pObj->Signed,
1, Vec_IntArray(vFanins), 0, NULL, NULL );
}
Vec_IntFree( vFanins );
return pDesign;
}
void Wlc_WriteNdr( Wlc_Ntk_t * pNtk, char * pFileName )
{
void * pDesign = Wlc_NtkToNdr( pNtk );
Ndr_Write( pFileName, pDesign );
Ndr_Delete( pDesign );
printf( "Dumped the current design into file \"%s\".\n", pFileName );
}
void Wlc_NtkToNdrTest( Wlc_Ntk_t * pNtk )
{
void * pDesign = Wlc_NtkToNdr( pNtk );
Wlc_Obj_t * pObj; int i;
char ** ppNames = ABC_ALLOC( char *, Wlc_NtkObjNum(pNtk) + 1 );
Wlc_NtkForEachObj( pNtk, pObj, i )
ppNames[i] = Wlc_ObjName(pNtk, i);
Ndr_WriteVerilog( NULL, pDesign, ppNames, 0 );
Ndr_Write( "test.ndr", pDesign );
Ndr_Delete( pDesign );
ABC_FREE( ppNames );
}
int Ndr_ObjReadRange( Ndr_Data_t * p, int Obj, int * End, int * Beg )
{
int * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_RANGE, &pArray );
int Signed = 0; *End = *Beg = 0;
if ( nArray == 0 )
return 0;
if ( nArray == 3 )
Signed = 1;
if ( nArray == 1 )
*End = *Beg = pArray[0];
else
*End = pArray[0], *Beg = pArray[1];
return Signed;
}
void Ndr_ObjReadConstant( Vec_Int_t * vFanins, char * pStr )
{
int i, k, Len = pStr ? strlen(pStr) : 0;
for ( k = 0; k < Len; k++ )
if ( pStr[k] == 'b' )
break;
if ( pStr == NULL || pStr[k] != 'b' )
{
printf( "Constants should be represented in binary Verilog notation <nbits>\'b<bits> as char strings (for example, \"4'b1010\").\n" );
return;
}
Vec_IntFill( vFanins, Abc_BitWordNum(Len-k-1), 0 );
for ( i = k+1; i < Len; i++ )
if ( pStr[i] == '1' )
Abc_InfoSetBit( (unsigned *)Vec_IntArray(vFanins), Len-i-1 );
else if ( pStr[i] != '0' )
printf( "Wrongn symbol (%c) in binary Verilog constant \"%s\".\n", pStr[i], pStr );
}
void Ndr_NtkPrintNodes( Wlc_Ntk_t * pNtk )
{
Wlc_Obj_t * pObj; int i, k;
printf( "Node IDs and their fanins:\n" );
Wlc_NtkForEachObj( pNtk, pObj, i )
{
int * pFanins = Wlc_ObjFanins(pObj);
printf( "%5d = ", i );
for ( k = 0; k < Wlc_ObjFaninNum(pObj); k++ )
printf( "%5d ", pFanins[k] );
for ( ; k < 4; k++ )
printf( " " );
printf( " Name Id %d ", Wlc_ObjNameId(pNtk, i) );
if ( Wlc_ObjIsPi(pObj) )
printf( " pi " );
if ( Wlc_ObjIsPo(pObj) )
printf( " po " );
printf( "\n" );
}
}
void Wlc_NtkCheckIntegrity( void * pData )
{
Ndr_Data_t * p = (Ndr_Data_t *)pData;
Vec_Int_t * vMap = Vec_IntAlloc( 100 );
int Mod = 2, Obj;
Ndr_ModForEachObj( p, Mod, Obj )
{
int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
if ( NameId == -1 )
{
int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
if ( Type != ABC_OPER_CO )
printf( "Internal object %d of type %s has no output name.\n", Obj, Abc_OperName(Type) );
continue;
}
if ( Vec_IntGetEntry(vMap, NameId) > 0 )
printf( "Output name %d is used more than once (obj %d and obj %d).\n", NameId, Vec_IntGetEntry(vMap, NameId), Obj );
Vec_IntSetEntry( vMap, NameId, Obj );
}
Ndr_ModForEachObj( p, Mod, Obj )
{
int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
int i, * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
for ( i = 0; i < nArray; i++ )
if ( Vec_IntGetEntry(vMap, pArray[i]) == 0 && !(Type == ABC_OPER_DFFRSE && (i >= 5 && i <= 7)) )
printf( "Input name %d appearing as fanin %d of obj %d is not used as output name in any object.\n", pArray[i], i, Obj );
}
Vec_IntFree( vMap );
}
Wlc_Ntk_t * Wlc_NtkFromNdr( void * pData )
{
Ndr_Data_t * p = (Ndr_Data_t *)pData;
Wlc_Obj_t * pObj; Vec_Int_t * vName2Obj, * vFanins = Vec_IntAlloc( 100 );
int Mod = 2, i, k, Obj, * pArray, fFound, NameId, NameIdMax;
unsigned char nDigits;
Vec_Wrd_t * vTruths = NULL; int nTruths[2] = {0};
Wlc_Ntk_t * pTemp, * pNtk = Wlc_NtkAlloc( "top", Ndr_DataObjNum(p, Mod)+1 );
Wlc_NtkCheckIntegrity( pData );
Vec_IntClear( &pNtk->vFfs );
Wlc_NtkCleanNameId( pNtk );
Ndr_ModForEachPi( p, Mod, Obj )
{
int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
int iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_PI, Signed, End, Beg );
int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
Wlc_ObjSetNameId( pNtk, iObj, NameId );
}
Ndr_ModForEachNode( p, Mod, Obj )
{
int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
Vec_Int_t F = {nArray, nArray, pArray}, * vTemp = &F;
int iObj = Wlc_ObjAlloc( pNtk, Ndr_TypeNdr2Wlc(Type), Signed, End, Beg );
int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
Vec_IntClear( vFanins );
Vec_IntAppend( vFanins, vTemp );
if ( Type == ABC_OPER_DFF )
{
if ( pNtk->vInits == NULL )
pNtk->vInits = Vec_IntAlloc( 100 );
if ( Vec_IntSize(vFanins) == 2 )
Vec_IntPush( pNtk->vInits, Vec_IntPop(vFanins) );
else Vec_IntPush( pNtk->vInits, -(End-Beg+1) );
pObj = Wlc_NtkObj(pNtk, iObj);
assert( Wlc_ObjType(pObj) == WLC_OBJ_FO );
Wlc_ObjSetNameId( pNtk, iObj, NameId );
Vec_IntPush( &pNtk->vFfs, NameId );
assert( Vec_IntSize(vFanins) == 1 );
Vec_IntPush( &pNtk->vFfs, Vec_IntEntry(vFanins, 0) );
continue;
}
if ( Type == ABC_OPER_DFFRSE )
Vec_IntPush( &pNtk->vFfs2, iObj );
if ( Type == ABC_OPER_LUT )
{
word * pTruth;
if ( vTruths == NULL )
vTruths = Vec_WrdStart( 1000 );
if ( NameId >= Vec_WrdSize(vTruths) )
Vec_WrdFillExtra( vTruths, 2*NameId, 0 );
pTruth = (word *)Ndr_ObjReadBodyP(p, Obj, NDR_FUNCTION);
Vec_WrdWriteEntry( vTruths, NameId, pTruth ? *pTruth : 0 );
nTruths[ pTruth != NULL ]++;
}
if ( Type == ABC_OPER_SLICE )
Vec_IntPushTwo( vFanins, End, Beg );
else if ( Type == ABC_OPER_CONST )
Ndr_ObjReadConstant( vFanins, (char *)Ndr_ObjReadBodyP(p, Obj, NDR_FUNCTION) );
else if ( Type == ABC_OPER_BIT_MUX && Vec_IntSize(vFanins) == 3 )
ABC_SWAP( int, Vec_IntEntryP(vFanins, 1)[0], Vec_IntEntryP(vFanins, 2)[0] );
Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), vFanins );
Wlc_ObjSetNameId( pNtk, iObj, NameId );
if ( Type == ABC_OPER_ARI_SMUL )
{
pObj = Wlc_NtkObj(pNtk, iObj);
assert( Wlc_ObjFaninNum(pObj) == 2 );
Wlc_ObjFanin0(pNtk, pObj)->Signed = 1;
Wlc_ObjFanin1(pNtk, pObj)->Signed = 1;
}
}
if ( nTruths[0] )
printf( "Warning! The number of LUTs without function is %d (out of %d).\n", nTruths[0], nTruths[0]+nTruths[1] );
Ndr_ModForEachPo( p, Mod, Obj )
{
int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
int iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_BUF, Signed, End, Beg );
int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
assert( nArray == 1 && NameId == -1 );
pObj = Wlc_NtkObj( pNtk, iObj );
Vec_IntFill( vFanins, 1, pArray[0] );
Wlc_ObjAddFanins( pNtk, pObj, vFanins );
Wlc_ObjSetCo( pNtk, pObj, 0 );
}
Vec_IntFree( vFanins );
vName2Obj = Vec_IntInvert( &pNtk->vNameIds, 0 );
Wlc_NtkForEachObj( pNtk, pObj, i )
{
int * pFanins = Wlc_ObjFanins(pObj);
for ( k = 0; k < Wlc_ObjFaninNum(pObj); k++ )
pFanins[k] = Vec_IntEntry(vName2Obj, pFanins[k]);
}
if ( pNtk->vInits )
{
Vec_IntForEachEntry( &pNtk->vFfs, NameId, i )
Vec_IntWriteEntry( &pNtk->vFfs, i, Vec_IntEntry(vName2Obj, NameId) );
Vec_IntForEachEntry( pNtk->vInits, NameId, i )
if ( NameId > 0 )
Vec_IntWriteEntry( pNtk->vInits, i, Vec_IntEntry(vName2Obj, NameId) );
assert( (Vec_IntSize(&pNtk->vFfs) & 1) == 0 );
assert( Vec_IntSize(&pNtk->vFfs) == 2 * Vec_IntSize(pNtk->vInits) );
Wlc_NtkForEachFf( pNtk, pObj, i )
if ( i & 1 )
Wlc_ObjSetCo( pNtk, pObj, 1 );
Vec_IntClear( &pNtk->vFfs );
pNtk->pInits = Wlc_PrsConvertInitValues( pNtk );
}
Vec_IntFree(vName2Obj);
NameIdMax = Vec_IntFindMax(&pNtk->vNameIds);
nDigits = (unsigned char)Abc_Base10Log( NameIdMax+1 );
pNtk->pManName = Abc_NamStart( NameIdMax+1, 10 );
for ( i = 1; i <= NameIdMax; i++ )
{
char pName[1000]; sprintf( pName, "s%0*d", nDigits, i );
NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, &fFound );
assert( !fFound && i == NameId );
}
pNtk = Wlc_NtkDupDfs( pTemp = pNtk, 0, 1 );
Wlc_NtkFree( pTemp );
if ( vTruths )
{
pNtk->vLutTruths = Vec_WrdStart( Wlc_NtkObjNumMax(pNtk) );
Wlc_NtkForEachObj( pNtk, pObj, i )
{
int iObj = Wlc_ObjId(pNtk, pObj);
int NameId = Wlc_ObjNameId(pNtk, iObj);
word Truth;
if ( pObj->Type != WLC_OBJ_LUT || NameId == 0 )
continue;
Truth = Vec_WrdEntry(vTruths, NameId);
assert( sizeof(void *) == 8 || Wlc_ObjFaninNum(pObj) < 6 );
Vec_WrdWriteEntry( pNtk->vLutTruths, iObj, Truth );
}
Vec_WrdFreeP( &vTruths );
}
pNtk->fMemPorts = 1; pNtk->fEasyFfs = 1; return pNtk;
}
void Ndr_DumpNdr( void * pDesign )
{
int i;
char ** pNames = ABC_CALLOC( char *, 10000 );
for ( i = 0; i < 10000; i++ )
{
char Buffer[100];
sprintf( Buffer, "s%d", i );
pNames[i] = Abc_UtilStrsav( Buffer );
}
Ndr_WriteVerilog( "temp.v", pDesign, pNames, 0 );
}
Wlc_Ntk_t * Wlc_ReadNdr( char * pFileName )
{
void * pData = Ndr_Read( pFileName );
Wlc_Ntk_t * pNtk = Wlc_NtkFromNdr( pData );
Abc_FrameInputNdr( Abc_FrameGetGlobalFrame(), pData );
return pNtk;
}
void Wlc_ReadNdrTest()
{
Wlc_Ntk_t * pNtk = Wlc_ReadNdr( "top.ndr" );
Wlc_WriteVer( pNtk, "top.v", 0, 0 );
Wlc_NtkFree( pNtk );
}
ABC_NAMESPACE_IMPL_END