diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2013-02-20 12:52:11 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2013-02-20 12:52:11 -0800 |
commit | f4c305fc468c5657a2bbae825261f3e4278ed6f8 (patch) | |
tree | b7f142b6c0aa6cb121947fc6d0ad48d8e79865d0 /src/aig/gia | |
parent | a82b0a8ad5887df664d474b58347296f93cec01c (diff) | |
download | abc-f4c305fc468c5657a2bbae825261f3e4278ed6f8.tar.gz abc-f4c305fc468c5657a2bbae825261f3e4278ed6f8.tar.bz2 abc-f4c305fc468c5657a2bbae825261f3e4278ed6f8.zip |
Adding STG generation (&era -d) and STG encoding (&read_stg <file>).
Diffstat (limited to 'src/aig/gia')
-rw-r--r-- | src/aig/gia/giaStg.c | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/aig/gia/giaStg.c b/src/aig/gia/giaStg.c index 80f12530..0cb9f4ea 100644 --- a/src/aig/gia/giaStg.c +++ b/src/aig/gia/giaStg.c @@ -43,10 +43,42 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ +int Gia_ManCreateOrGate( Gia_Man_t * p, Vec_Int_t * vLits ) +{ + if ( Vec_IntSize(vLits) == 0 ) + return 0; + while ( Vec_IntSize(vLits) > 1 ) + { + int i, k = 0, Lit1, Lit2, LitRes; + Vec_IntForEachEntryDouble( vLits, Lit1, Lit2, i ) + { + LitRes = Gia_ManHashOr( p, Lit1, Lit2 ); + Vec_IntWriteEntry( vLits, k++, LitRes ); + } + if ( Vec_IntSize(vLits) & 1 ) + Vec_IntWriteEntry( vLits, k++, Vec_IntEntryLast(vLits) ); + Vec_IntShrink( vLits, k ); + } + assert( Vec_IntSize(vLits) == 1 ); + return Vec_IntEntry(vLits, 0); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ Gia_Man_t * Gia_ManStgOneHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates ) { Gia_Man_t * p; - Vec_Int_t * vInMints, * vCurs, * vOuts, * vNexts; + Vec_Int_t * vInMints, * vCurs, * vVec; + Vec_Vec_t * vLitsNext, * vLitsOuts; int i, b, LitC, Lit; assert( Vec_IntSize(vLines) % 4 == 0 ); @@ -71,11 +103,9 @@ Gia_Man_t * Gia_ManStgOneHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStat for ( i = 0; i < nStates; i++ ) Vec_IntPush( vCurs, Abc_Var2Lit( 1+nIns+i, !i ) ); - // start outputs and current states - vOuts = Vec_IntStart( nOuts ); - vNexts = Vec_IntStart( nStates ); - // go through the lines + vLitsNext = Vec_VecStart( nStates ); + vLitsOuts = Vec_VecStart( nOuts ); for ( i = 0; i < Vec_IntSize(vLines); ) { int iMint = Vec_IntEntry(vLines, i++); @@ -89,33 +119,34 @@ Gia_Man_t * Gia_ManStgOneHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStat // create condition LitC = Gia_ManHashAnd( p, Vec_IntEntry(vInMints, iMint), Vec_IntEntry(vCurs, iCur) ); // update next state - Lit = Gia_ManHashOr( p, LitC, Vec_IntEntry(vNexts, iNext) ); - Vec_IntWriteEntry( vNexts, iNext, Lit ); +// Lit = Gia_ManHashOr( p, LitC, Vec_IntEntry(vNexts, iNext) ); +// Vec_IntWriteEntry( vNexts, iNext, Lit ); + Vec_VecPushInt( vLitsNext, iNext, LitC ); // update outputs for ( b = 0; b < nOuts; b++ ) if ( (iOut >> b) & 1 ) { - Lit = Gia_ManHashOr( p, LitC, Vec_IntEntry(vOuts, b) ); - Vec_IntWriteEntry( vOuts, b, Lit ); +// Lit = Gia_ManHashOr( p, LitC, Vec_IntEntry(vOuts, b) ); +// Vec_IntWriteEntry( vOuts, b, Lit ); + Vec_VecPushInt( vLitsOuts, b, LitC ); } } + Vec_IntFree( vInMints ); + Vec_IntFree( vCurs ); // create POs - Vec_IntForEachEntry( vOuts, Lit, i ) - Gia_ManAppendCo( p, Lit ); + Vec_VecForEachLevelInt( vLitsOuts, vVec, i ) + Gia_ManAppendCo( p, Gia_ManCreateOrGate(p, vVec) ); + Vec_VecFree( vLitsOuts ); // create next states - Vec_IntForEachEntry( vNexts, Lit, i ) - Gia_ManAppendCo( p, Abc_LitNotCond(Lit, !i) ); + Vec_VecForEachLevelInt( vLitsNext, vVec, i ) + Gia_ManAppendCo( p, Abc_LitNotCond( Gia_ManCreateOrGate(p, vVec), !i ) ); + Vec_VecFree( vLitsNext ); Gia_ManSetRegNum( p, nStates ); Gia_ManHashStop( p ); - Vec_IntFree( vInMints ); - Vec_IntFree( vCurs ); - Vec_IntFree( vOuts ); - Vec_IntFree( vNexts ); - assert( !Gia_ManHasDangling(p) ); return p; } @@ -171,6 +202,11 @@ Vec_Int_t * Gia_ManStgReadLines( char * pFileName, int * pnIns, int * pnOuts, in char * pToken; int Number, nInputs = -1, nOutputs = -1, nStates = 1; FILE * pFile; + if ( !strcmp(pFileName + strlen(pFileName) - 3, "aig") ) + { + printf( "Input file \"%s\" has extension \"aig\".\n", pFileName, "aig" ); + return NULL; + } pFile = fopen( pFileName, "rb" ); if ( pFile == NULL ) { |