diff options
Diffstat (limited to 'src/map/mio/mioUtils.c')
-rw-r--r-- | src/map/mio/mioUtils.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c index 9cd44cba..c7180e1c 100644 --- a/src/map/mio/mioUtils.c +++ b/src/map/mio/mioUtils.c @@ -288,6 +288,99 @@ void Mio_WriteLibrary( FILE * pFile, Mio_Library_t * pLib, int fPrintSops, int f /**Function************************************************************* + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Exp_PrintNodeVerilog( FILE * pFile, int nVars, Vec_Int_t * p, Vec_Ptr_t * vNames, int Node, int fCompl ) +{ + extern void Exp_PrintLitVerilog( FILE * pFile, int nVars, Vec_Int_t * p, Vec_Ptr_t * vNames, int Lit ); + if ( Vec_IntEntry(p, 2*Node+1) >= 2*nVars ) + fprintf( pFile, "(" ); + Exp_PrintLitVerilog( pFile, nVars, p, vNames, Vec_IntEntry(p, 2*Node+1) ^ fCompl ); + if ( Vec_IntEntry(p, 2*Node+1) >= 2*nVars ) + fprintf( pFile, ")" ); + fprintf( pFile, " %c ", fCompl ? '|' : '&' ); + if ( Vec_IntEntry(p, 2*Node+0) >= 2*nVars ) + fprintf( pFile, "(" ); + Exp_PrintLitVerilog( pFile, nVars, p, vNames, Vec_IntEntry(p, 2*Node+0) ^ fCompl ); + if ( Vec_IntEntry(p, 2*Node+0) >= 2*nVars ) + fprintf( pFile, ")" ); +} +void Exp_PrintLitVerilog( FILE * pFile, int nVars, Vec_Int_t * p, Vec_Ptr_t * vNames, int Lit ) +{ + if ( Lit == EXP_CONST0 ) + fprintf( pFile, "1\'b0" ); + else if ( Lit == EXP_CONST1 ) + fprintf( pFile, "1\'b1" ); + else if ( Lit < 2 * nVars ) + fprintf( pFile, "%s%s", (Lit&1) ? "~" : "", (char *)Vec_PtrEntry(vNames, Lit/2) ); + else + Exp_PrintNodeVerilog( pFile, nVars, p, vNames, Lit/2-nVars, Lit&1 ); +} +void Exp_PrintVerilog( FILE * pFile, int nVars, Vec_Int_t * p, Vec_Ptr_t * vNames ) +{ + Exp_PrintLitVerilog( pFile, nVars, p, vNames, Vec_IntEntryLast(p) ); +} +void Mio_WriteGateVerilog( FILE * pFile, Mio_Gate_t * pGate, Vec_Ptr_t * vNames ) +{ + char * pName; int i; + fprintf( pFile, "module %s ( ", pGate->pName ); + fprintf( pFile, "%s", pGate->pOutName ); + Vec_PtrForEachEntry( char *, vNames, pName, i ) + fprintf( pFile, ", %s", pName ); + fprintf( pFile, " );\n" ); + fprintf( pFile, " output %s;\n", pGate->pOutName ); + if ( Vec_PtrSize(vNames) > 0 ) + { + fprintf( pFile, " input %s", (char *)Vec_PtrEntry(vNames, 0) ); + Vec_PtrForEachEntryStart( char *, vNames, pName, i, 1 ) + fprintf( pFile, ", %s", pName ); + fprintf( pFile, ";\n" ); + } + fprintf( pFile, " assign %s = ", pGate->pOutName ); + Exp_PrintVerilog( pFile, Vec_PtrSize(vNames), pGate->vExpr, vNames ); + fprintf( pFile, ";\n" ); + fprintf( pFile, "endmodule\n\n" ); +} +void Mio_WriteLibraryVerilog( FILE * pFile, Mio_Library_t * pLib, int fPrintSops, int fShort, int fSelected ) +{ + Mio_Gate_t * pGate; + Mio_Pin_t * pPin; + Vec_Ptr_t * vGates = Vec_PtrAlloc( 1000 ); + Vec_Ptr_t * vNames = Vec_PtrAlloc( 100 ); + int i, nCells; + if ( fSelected ) + { + Mio_Cell2_t * pCells = Mio_CollectRootsNewDefault2( 6, &nCells, 0 ); + for ( i = 0; i < nCells; i++ ) + Vec_PtrPush( vGates, pCells[i].pMioGate ); + ABC_FREE( pCells ); + } + else + { + for ( i = 0; i < pLib->nGates; i++ ) + Vec_PtrPush( vGates, pLib->ppGates0[i] ); + } + fprintf( pFile, "// Verilog for genlib library \"%s\" with %d gates written by ABC on %s\n\n", pLib->pName, Vec_PtrSize(vGates), Extra_TimeStamp() ); + Vec_PtrForEachEntry( Mio_Gate_t *, vGates, pGate, i ) + { + Vec_PtrClear( vNames ); + Mio_GateForEachPin( pGate, pPin ) + Vec_PtrPush( vNames, pPin->pName ); + Mio_WriteGateVerilog( pFile, pGate, vNames ); + } + Vec_PtrFree( vNames ); + Vec_PtrFree( vGates ); +} + +/**Function************************************************************* + Synopsis [Compares the max delay of two gates.] Description [] |