src/base/abc/abcSop.c File Reference

#include "abc.h"
Include dependency graph for abcSop.c:

Go to the source code of this file.

Functions

char * Abc_SopRegister (Extra_MmFlex_t *pMan, char *pName)
char * Abc_SopStart (Extra_MmFlex_t *pMan, int nCubes, int nVars)
char * Abc_SopCreateConst1 (Extra_MmFlex_t *pMan)
char * Abc_SopCreateConst0 (Extra_MmFlex_t *pMan)
char * Abc_SopCreateAnd2 (Extra_MmFlex_t *pMan, int fCompl0, int fCompl1)
char * Abc_SopCreateAnd (Extra_MmFlex_t *pMan, int nVars, int *pfCompl)
char * Abc_SopCreateNand (Extra_MmFlex_t *pMan, int nVars)
char * Abc_SopCreateOr (Extra_MmFlex_t *pMan, int nVars, int *pfCompl)
char * Abc_SopCreateOrMultiCube (Extra_MmFlex_t *pMan, int nVars, int *pfCompl)
char * Abc_SopCreateNor (Extra_MmFlex_t *pMan, int nVars)
char * Abc_SopCreateXor (Extra_MmFlex_t *pMan, int nVars)
char * Abc_SopCreateXorSpecial (Extra_MmFlex_t *pMan, int nVars)
char * Abc_SopCreateNxor (Extra_MmFlex_t *pMan, int nVars)
char * Abc_SopCreateMux (Extra_MmFlex_t *pMan)
char * Abc_SopCreateInv (Extra_MmFlex_t *pMan)
char * Abc_SopCreateBuf (Extra_MmFlex_t *pMan)
char * Abc_SopCreateFromTruth (Extra_MmFlex_t *pMan, int nVars, unsigned *pTruth)
char * Abc_SopCreateFromIsop (Extra_MmFlex_t *pMan, int nVars, Vec_Int_t *vCover)
int Abc_SopGetCubeNum (char *pSop)
int Abc_SopGetLitNum (char *pSop)
int Abc_SopGetVarNum (char *pSop)
int Abc_SopGetPhase (char *pSop)
int Abc_SopGetIthCareLit (char *pSop, int i)
void Abc_SopComplement (char *pSop)
bool Abc_SopIsComplement (char *pSop)
bool Abc_SopIsConst0 (char *pSop)
bool Abc_SopIsConst1 (char *pSop)
bool Abc_SopIsBuf (char *pSop)
bool Abc_SopIsInv (char *pSop)
bool Abc_SopIsAndType (char *pSop)
bool Abc_SopIsOrType (char *pSop)
int Abc_SopIsExorType (char *pSop)
bool Abc_SopCheck (char *pSop, int nFanins)
char * Abc_SopFromTruthBin (char *pTruth)
char * Abc_SopFromTruthHex (char *pTruth)
char * Abc_SopEncoderPos (Extra_MmFlex_t *pMan, int iValue, int nValues)
char * Abc_SopEncoderLog (Extra_MmFlex_t *pMan, int iBit, int nValues)
char * Abc_SopDecoderPos (Extra_MmFlex_t *pMan, int nValues)
char * Abc_SopDecoderLog (Extra_MmFlex_t *pMan, int nValues)

Function Documentation

bool Abc_SopCheck ( char *  pSop,
int  nFanins 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 758 of file abcSop.c.

00759 {
00760     char * pCubes, * pCubesOld;
00761     int fFound0 = 0, fFound1 = 0;
00762 
00763     // check the logic function of the node
00764     for ( pCubes = pSop; *pCubes; pCubes++ )
00765     {
00766         // get the end of the next cube
00767         for ( pCubesOld = pCubes; *pCubes != ' '; pCubes++ );
00768         // compare the distance
00769         if ( pCubes - pCubesOld != nFanins )
00770         {
00771             fprintf( stdout, "Abc_SopCheck: SOP has a mismatch between its cover size (%d) and its fanin number (%d).\n",
00772                 pCubes - pCubesOld, nFanins );
00773             return 0;
00774         }
00775         // check the output values for this cube
00776         pCubes++;
00777         if ( *pCubes == '0' )
00778             fFound0 = 1;
00779         else if ( *pCubes == '1' )
00780             fFound1 = 1;
00781         else if ( *pCubes != 'x' && *pCubes != 'n' )
00782         {
00783             fprintf( stdout, "Abc_SopCheck: SOP has a strange character (%c) in the output part of its cube.\n", *pCubes );
00784             return 0;
00785         }
00786         // check the last symbol (new line)
00787         pCubes++;
00788         if ( *pCubes != '\n' )
00789         {
00790             fprintf( stdout, "Abc_SopCheck: SOP has a cube without new line in the end.\n" );
00791             return 0;
00792         }
00793     }
00794     if ( fFound0 && fFound1 )
00795     {
00796         fprintf( stdout, "Abc_SopCheck: SOP has cubes in both phases.\n" );
00797         return 0;
00798     }
00799     return 1;
00800 }

void Abc_SopComplement ( char *  pSop  ) 

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 560 of file abcSop.c.

00561 {
00562     char * pCur;
00563     for ( pCur = pSop; *pCur; pCur++ )
00564         if ( *pCur == '\n' )
00565         {
00566             if ( *(pCur - 1) == '0' )
00567                 *(pCur - 1) = '1';
00568             else if ( *(pCur - 1) == '1' )
00569                 *(pCur - 1) = '0';
00570             else if ( *(pCur - 1) == 'x' )
00571                 *(pCur - 1) = 'n';
00572             else if ( *(pCur - 1) == 'n' )
00573                 *(pCur - 1) = 'x';
00574             else
00575                 assert( 0 );
00576         }
00577 }

char* Abc_SopCreateAnd ( Extra_MmFlex_t pMan,
int  nVars,
int *  pfCompl 
)

Function*************************************************************

Synopsis [Creates the multi-input AND cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 159 of file abcSop.c.

00160 {
00161     char * pSop;
00162     int i;
00163     pSop = Abc_SopStart( pMan, 1, nVars );
00164     for ( i = 0; i < nVars; i++ )
00165         pSop[i] = '1' - (pfCompl? pfCompl[i] : 0);
00166     pSop[nVars + 1] = '1';
00167     return pSop;
00168 }

char* Abc_SopCreateAnd2 ( Extra_MmFlex_t pMan,
int  fCompl0,
int  fCompl1 
)

Function*************************************************************

Synopsis [Creates the AND2 cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 136 of file abcSop.c.

00137 {
00138     char Buffer[6];
00139     Buffer[0] = '1' - fCompl0;
00140     Buffer[1] = '1' - fCompl1;
00141     Buffer[2] = ' ';
00142     Buffer[3] = '1';
00143     Buffer[4] = '\n';
00144     Buffer[5] = 0;
00145     return Abc_SopRegister( pMan, Buffer );
00146 }

char* Abc_SopCreateBuf ( Extra_MmFlex_t pMan  ) 

Function*************************************************************

Synopsis [Creates the buf cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 358 of file abcSop.c.

00359 {
00360     return Abc_SopRegister(pMan, "1 1\n");
00361 }

char* Abc_SopCreateConst0 ( Extra_MmFlex_t pMan  ) 

Function*************************************************************

Synopsis [Creates the constant 1 cover with 0 variables.]

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file abcSop.c.

00121 {
00122     return Abc_SopRegister( pMan, " 0\n" );
00123 }

char* Abc_SopCreateConst1 ( Extra_MmFlex_t pMan  ) 

Function*************************************************************

Synopsis [Creates the constant 1 cover with 0 variables.]

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file abcSop.c.

00105 {
00106     return Abc_SopRegister( pMan, " 1\n" );
00107 }

char* Abc_SopCreateFromIsop ( Extra_MmFlex_t pMan,
int  nVars,
Vec_Int_t vCover 
)

Function*************************************************************

Synopsis [Creates the cover from the ISOP computed from TT.]

Description []

SideEffects []

SeeAlso []

Definition at line 413 of file abcSop.c.

00414 {
00415     char * pSop, * pCube;
00416     int i, k, Entry, Literal;
00417     assert( Vec_IntSize(vCover) > 0 );
00418     if ( Vec_IntSize(vCover) == 0 )
00419         return NULL;
00420     // start the cover
00421     pSop = Abc_SopStart( pMan, Vec_IntSize(vCover), nVars );
00422     // create cubes
00423     Vec_IntForEachEntry( vCover, Entry, i )
00424     {
00425         pCube = pSop + i * (nVars + 3);
00426         for ( k = 0; k < nVars; k++ )
00427         {
00428             Literal = 3 & (Entry >> (k << 1));
00429             if ( Literal == 1 )
00430                 pCube[k] = '0';
00431             else if ( Literal == 2 )
00432                 pCube[k] = '1';
00433             else if ( Literal != 0 )
00434                 assert( 0 );
00435         }
00436     }
00437     return pSop;
00438 }

char* Abc_SopCreateFromTruth ( Extra_MmFlex_t pMan,
int  nVars,
unsigned *  pTruth 
)

Function*************************************************************

Synopsis [Creates the arbitrary cover from the truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 374 of file abcSop.c.

00375 {
00376     char * pSop, * pCube;
00377     int nMints, Counter, i, k;
00378     // count the number of true minterms
00379     Counter = 0;
00380     nMints = (1 << nVars);
00381     for ( i = 0; i < nMints; i++ )
00382         Counter += ((pTruth[i>>5] & (1 << (i&31))) > 0);
00383     // SOP is not well-defined if the truth table is constant 0
00384     assert( Counter > 0 );
00385     if ( Counter == 0 )
00386         return NULL;
00387     // start the cover
00388     pSop = Abc_SopStart( pMan, Counter, nVars );
00389     // create true minterms
00390     Counter = 0;
00391     for ( i = 0; i < nMints; i++ )
00392         if ( (pTruth[i>>5] & (1 << (i&31))) > 0 )
00393         {
00394             pCube = pSop + Counter * (nVars + 3);
00395             for ( k = 0; k < nVars; k++ )
00396                 pCube[k] = '0' + ((i & (1 << k)) > 0);
00397             Counter++;
00398         }
00399     return pSop;
00400 }

char* Abc_SopCreateInv ( Extra_MmFlex_t pMan  ) 

Function*************************************************************

Synopsis [Creates the inv cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 342 of file abcSop.c.

00343 {
00344     return Abc_SopRegister(pMan, "0 1\n");
00345 }

char* Abc_SopCreateMux ( Extra_MmFlex_t pMan  ) 

Function*************************************************************

Synopsis [Creates the MUX cover.]

Description [The first input of MUX is the control. The second input is DATA1. The third input is DATA0.]

SideEffects []

SeeAlso []

Definition at line 326 of file abcSop.c.

00327 {
00328     return Abc_SopRegister(pMan, "11- 1\n0-1 1\n");
00329 }

char* Abc_SopCreateNand ( Extra_MmFlex_t pMan,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the multi-input NAND cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 181 of file abcSop.c.

00182 {
00183     char * pSop;
00184     int i;
00185     pSop = Abc_SopStart( pMan, 1, nVars );
00186     for ( i = 0; i < nVars; i++ )
00187         pSop[i] = '1';
00188     pSop[nVars + 1] = '0';
00189     return pSop;
00190 }

char* Abc_SopCreateNor ( Extra_MmFlex_t pMan,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the multi-input NOR cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file abcSop.c.

00251 {
00252     char * pSop;
00253     int i;
00254     pSop = Abc_SopStart( pMan, 1, nVars );
00255     for ( i = 0; i < nVars; i++ )
00256         pSop[i] = '0';
00257     return pSop;
00258 }

char* Abc_SopCreateNxor ( Extra_MmFlex_t pMan,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the multi-input XNOR cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 308 of file abcSop.c.

00309 {
00310     assert( nVars == 2 );
00311     return Abc_SopRegister(pMan, "11 1\n00 1\n");
00312 }

char* Abc_SopCreateOr ( Extra_MmFlex_t pMan,
int  nVars,
int *  pfCompl 
)

Function*************************************************************

Synopsis [Creates the multi-input OR cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 203 of file abcSop.c.

00204 {
00205     char * pSop;
00206     int i;
00207     pSop = Abc_SopStart( pMan, 1, nVars );
00208     for ( i = 0; i < nVars; i++ )
00209         pSop[i] = '0' + (pfCompl? pfCompl[i] : 0);
00210     pSop[nVars + 1] = '0';
00211     return pSop;
00212 }

char* Abc_SopCreateOrMultiCube ( Extra_MmFlex_t pMan,
int  nVars,
int *  pfCompl 
)

Function*************************************************************

Synopsis [Creates the multi-input OR cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 225 of file abcSop.c.

00226 {
00227     char * pSop, * pCube;
00228     int i;
00229     pSop = Abc_SopStart( pMan, nVars, nVars );
00230     i = 0;
00231     Abc_SopForEachCube( pSop, nVars, pCube )
00232     {
00233         pCube[i] = '1' - (pfCompl? pfCompl[i] : 0);
00234         i++;
00235     }
00236     return pSop;
00237 }

char* Abc_SopCreateXor ( Extra_MmFlex_t pMan,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the multi-input XOR cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 271 of file abcSop.c.

00272 {
00273     assert( nVars == 2 );
00274     return Abc_SopRegister(pMan, "01 1\n10 1\n");
00275 }

char* Abc_SopCreateXorSpecial ( Extra_MmFlex_t pMan,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the multi-input XOR cover (special case).]

Description []

SideEffects []

SeeAlso []

Definition at line 288 of file abcSop.c.

00289 {
00290     char * pSop;
00291     pSop = Abc_SopCreateAnd( pMan, nVars, NULL );
00292     pSop[nVars+1] = 'x';
00293     assert( pSop[nVars+2] == '\n' );
00294     return pSop;
00295 }

char* Abc_SopDecoderLog ( Extra_MmFlex_t pMan,
int  nValues 
)

Function*************************************************************

Synopsis [Creates the decover node.]

Description [Produces MV-SOP for BLIF-MV representation.]

SideEffects []

SeeAlso []

Definition at line 1048 of file abcSop.c.

01049 {
01050     char * pResult;
01051     Vec_Str_t * vSop;
01052     int i, b, nBits = Extra_Base2Log(nValues);
01053     assert( nValues > 1 && nValues <= (1<<nBits) );
01054     vSop = Vec_StrAlloc( 100 );
01055     for ( i = 0; i < nValues; i++ )
01056     {
01057         for ( b = 0; b < nBits; b++ )
01058         {
01059             Vec_StrPrintNum( vSop, (int)((i & (1 << b)) > 0) );
01060             Vec_StrPush( vSop, ' ' );
01061         }
01062         Vec_StrPrintNum( vSop, i );
01063         Vec_StrPush( vSop, '\n' );
01064     }
01065     Vec_StrPush( vSop, 0 );
01066     pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
01067     Vec_StrFree( vSop );
01068     return pResult;
01069 }

char* Abc_SopDecoderPos ( Extra_MmFlex_t pMan,
int  nValues 
)

Function*************************************************************

Synopsis [Creates the decoder node.]

Description [Produces MV-SOP for BLIF-MV representation.]

SideEffects []

SeeAlso []

Definition at line 1012 of file abcSop.c.

01013 {
01014     char * pResult;
01015     Vec_Str_t * vSop;
01016     int i, k;
01017     assert( nValues > 1 );
01018     vSop = Vec_StrAlloc( 100 );
01019     for ( i = 0; i < nValues; i++ )
01020     {
01021         for ( k = 0; k < nValues; k++ )
01022         {
01023             if ( k == i )
01024                 Vec_StrPrintStr( vSop, "1 " );
01025             else
01026                 Vec_StrPrintStr( vSop, "- " );
01027         }
01028         Vec_StrPrintNum( vSop, i );
01029         Vec_StrPush( vSop, '\n' );
01030     }
01031     Vec_StrPush( vSop, 0 );
01032     pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
01033     Vec_StrFree( vSop );
01034     return pResult;
01035 }

char* Abc_SopEncoderLog ( Extra_MmFlex_t pMan,
int  iBit,
int  nValues 
)

Function*************************************************************

Synopsis [Creates one encoder node.]

Description [Produces MV-SOP for BLIF-MV representation.]

SideEffects []

SeeAlso []

Definition at line 968 of file abcSop.c.

00969 {
00970     char * pResult;
00971     Vec_Str_t * vSop;
00972     int v, Counter, fFirst = 1, nBits = Extra_Base2Log(nValues);
00973     assert( iBit < nBits );
00974     // count the number of literals
00975     Counter = 0;
00976     for ( v = 0; v < nValues; v++ )
00977         Counter += ( (v & (1 << iBit)) > 0 );
00978     // create the cover
00979     vSop = Vec_StrAlloc( 100 );
00980     Vec_StrPrintStr( vSop, "d0\n" );
00981     if ( Counter > 1 )
00982         Vec_StrPrintStr( vSop, "(" );
00983     for ( v = 0; v < nValues; v++ )
00984         if ( v & (1 << iBit) )
00985         {
00986             if ( fFirst )
00987                 fFirst = 0;
00988             else
00989                 Vec_StrPush( vSop, ',' );
00990             Vec_StrPrintNum( vSop, v );
00991         }
00992     if ( Counter > 1 )
00993         Vec_StrPrintStr( vSop, ")" );
00994     Vec_StrPrintStr( vSop, " 1\n" );
00995     Vec_StrPush( vSop, 0 );
00996     pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
00997     Vec_StrFree( vSop );
00998     return pResult;
00999 }

char* Abc_SopEncoderPos ( Extra_MmFlex_t pMan,
int  iValue,
int  nValues 
)

Function*************************************************************

Synopsis [Creates one encoder node.]

Description [Produces MV-SOP for BLIF-MV representation.]

SideEffects []

SeeAlso []

Definition at line 949 of file abcSop.c.

00950 {
00951     char Buffer[32];
00952     assert( iValue < nValues );
00953     sprintf( Buffer, "d0\n%d 1\n", iValue );
00954     return Abc_SopRegister( pMan, Buffer );
00955 }

char* Abc_SopFromTruthBin ( char *  pTruth  ) 

Function*************************************************************

Synopsis [Derives SOP from the truth table representation.]

Description [Truth table is expected to be in the hexadecimal notation.]

SideEffects []

SeeAlso []

Definition at line 814 of file abcSop.c.

00815 {
00816     char * pSopCover, * pCube;
00817     int nTruthSize, nVars, Digit, Length, Mint, i, b;
00818     Vec_Int_t * vMints;
00819 
00820     // get the number of variables
00821     nTruthSize = strlen(pTruth);
00822     nVars = Extra_Base2Log( nTruthSize );
00823     if ( nTruthSize != (1 << (nVars)) )
00824     {
00825         printf( "String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
00826         return NULL;
00827     }
00828 
00829     // collect the on-set minterms
00830     vMints = Vec_IntAlloc( 100 );
00831     for ( i = 0; i < nTruthSize; i++ )
00832     {
00833         if ( pTruth[i] >= '0' && pTruth[i] <= '1' )
00834             Digit = pTruth[i] - '0';
00835         else
00836         {
00837             printf( "String %s does not look like a binary representation of the truth table.\n", pTruth );
00838             return NULL;
00839         }
00840         if ( Digit == 1 )
00841             Vec_IntPush( vMints, nTruthSize - 1 - i );
00842     }
00843     if ( Vec_IntSize( vMints ) == 0 || Vec_IntSize( vMints ) == nTruthSize )
00844     {
00845         Vec_IntFree( vMints );
00846         printf( "Cannot create constant function.\n" );
00847         return NULL;
00848     }
00849 
00850     // create the SOP representation of the minterms
00851     Length = Vec_IntSize(vMints) * (nVars + 3);
00852     pSopCover = ALLOC( char, Length + 1 );
00853     pSopCover[Length] = 0;
00854     Vec_IntForEachEntry( vMints, Mint, i )
00855     {
00856         pCube = pSopCover + i * (nVars + 3);
00857         for ( b = 0; b < nVars; b++ )
00858             if ( Mint & (1 << (nVars-1-b)) )
00859 //            if ( Mint & (1 << b) )
00860                 pCube[b] = '1';
00861             else
00862                 pCube[b] = '0';
00863         pCube[nVars + 0] = ' ';
00864         pCube[nVars + 1] = '1';
00865         pCube[nVars + 2] = '\n';
00866     }
00867     Vec_IntFree( vMints );
00868     return pSopCover;
00869 }

char* Abc_SopFromTruthHex ( char *  pTruth  ) 

Function*************************************************************

Synopsis [Derives SOP from the truth table representation.]

Description [Truth table is expected to be in the hexadecimal notation.]

SideEffects []

SeeAlso []

Definition at line 882 of file abcSop.c.

00883 {
00884     char * pSopCover, * pCube;
00885     int nTruthSize, nVars, Digit, Length, Mint, i, b;
00886     Vec_Int_t * vMints;
00887 
00888     // get the number of variables
00889     nTruthSize = strlen(pTruth);
00890     nVars = Extra_Base2Log( nTruthSize ) + 2;
00891     if ( nTruthSize != (1 << (nVars-2)) )
00892     {
00893         printf( "String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
00894         return NULL;
00895     }
00896 
00897     // collect the on-set minterms
00898     vMints = Vec_IntAlloc( 100 );
00899     for ( i = 0; i < nTruthSize; i++ )
00900     {
00901         if ( pTruth[i] >= '0' && pTruth[i] <= '9' )
00902             Digit = pTruth[i] - '0';
00903         else if ( pTruth[i] >= 'a' && pTruth[i] <= 'f' )
00904             Digit = 10 + pTruth[i] - 'a';
00905         else if ( pTruth[i] >= 'A' && pTruth[i] <= 'F' )
00906             Digit = 10 + pTruth[i] - 'A';
00907         else
00908         {
00909             printf( "String %s does not look like a hexadecimal representation of the truth table.\n", pTruth );
00910             return NULL;
00911         }
00912         for ( b = 0; b < 4; b++ )
00913             if ( Digit & (1 << b) )
00914                 Vec_IntPush( vMints, 4*(nTruthSize-1-i)+b );
00915     }
00916 
00917     // create the SOP representation of the minterms
00918     Length = Vec_IntSize(vMints) * (nVars + 3);
00919     pSopCover = ALLOC( char, Length + 1 );
00920     pSopCover[Length] = 0;
00921     Vec_IntForEachEntry( vMints, Mint, i )
00922     {
00923         pCube = pSopCover + i * (nVars + 3);
00924         for ( b = 0; b < nVars; b++ )
00925 //            if ( Mint & (1 << (nVars-1-b)) )
00926             if ( Mint & (1 << b) )
00927                 pCube[b] = '1';
00928             else
00929                 pCube[b] = '0';
00930         pCube[nVars + 0] = ' ';
00931         pCube[nVars + 1] = '1';
00932         pCube[nVars + 2] = '\n';
00933     }
00934     Vec_IntFree( vMints );
00935     return pSopCover;
00936 }

int Abc_SopGetCubeNum ( char *  pSop  ) 

Function*************************************************************

Synopsis [Reads the number of cubes in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 451 of file abcSop.c.

00452 {
00453     char * pCur;
00454     int nCubes = 0;
00455     if ( pSop == NULL )
00456         return 0;
00457     for ( pCur = pSop; *pCur; pCur++ )
00458         nCubes += (*pCur == '\n');
00459     return nCubes;
00460 }

int Abc_SopGetIthCareLit ( char *  pSop,
int  i 
)

Function*************************************************************

Synopsis [Returns the i-th literal of the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 538 of file abcSop.c.

00539 {
00540     char * pCube;
00541     int nVars;
00542     nVars = Abc_SopGetVarNum( pSop );
00543     Abc_SopForEachCube( pSop, nVars, pCube )
00544         if ( pCube[i] != '-' )
00545             return pCube[i] - '0';
00546     return -1;
00547 }

int Abc_SopGetLitNum ( char *  pSop  ) 

Function*************************************************************

Synopsis [Reads the number of SOP literals in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 473 of file abcSop.c.

00474 {
00475     char * pCur;
00476     int nLits = 0;
00477     if ( pSop == NULL )
00478         return 0;
00479     for ( pCur = pSop; *pCur; pCur++ )
00480     {
00481         nLits  -= (*pCur == '\n');
00482         nLits  += (*pCur == '0' || *pCur == '1');
00483     }
00484     return nLits;
00485 }

int Abc_SopGetPhase ( char *  pSop  ) 

Function*************************************************************

Synopsis [Reads the phase of the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 516 of file abcSop.c.

00517 {
00518     int nVars = Abc_SopGetVarNum( pSop );
00519     if ( pSop[nVars+1] == '0' || pSop[nVars+1] == 'n' )
00520         return 0;
00521     if ( pSop[nVars+1] == '1' || pSop[nVars+1] == 'x' )
00522         return 1;
00523     assert( 0 );
00524     return -1;
00525 }

int Abc_SopGetVarNum ( char *  pSop  ) 

Function*************************************************************

Synopsis [Reads the number of variables in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 498 of file abcSop.c.

00499 {
00500     char * pCur;
00501     for ( pCur = pSop; *pCur != '\n'; pCur++ );
00502     return pCur - pSop - 2;
00503 }

bool Abc_SopIsAndType ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is AND with possibly complemented inputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 683 of file abcSop.c.

00684 {
00685     char * pCur;
00686     if ( Abc_SopGetCubeNum(pSop) != 1 )
00687         return 0;
00688     for ( pCur = pSop; *pCur != ' '; pCur++ )
00689         if ( *pCur == '-' )
00690             return 0;
00691     if ( pCur[1] != '1' )
00692         return 0;
00693     return 1;
00694 }

bool Abc_SopIsBuf ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is constant 1.]

Description []

SideEffects []

SeeAlso []

Definition at line 643 of file abcSop.c.

00644 {
00645     if ( pSop[4] != 0 )
00646         return 0;
00647     if ( (pSop[0] == '1' && pSop[2] == '1') || (pSop[0] == '0' && pSop[2] == '0') )
00648         return 1;
00649     return 0;
00650 }

bool Abc_SopIsComplement ( char *  pSop  ) 

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 590 of file abcSop.c.

00591 {
00592     char * pCur;
00593     for ( pCur = pSop; *pCur; pCur++ )
00594         if ( *pCur == '\n' )
00595             return (int)(*(pCur - 1) == '0' || *(pCur - 1) == 'n');
00596     assert( 0 );
00597     return 0;
00598 }

bool Abc_SopIsConst0 ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is constant 0.]

Description []

SideEffects []

SeeAlso []

Definition at line 611 of file abcSop.c.

00612 {
00613     return pSop[0] == ' ' && pSop[1] == '0';
00614 }

bool Abc_SopIsConst1 ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is constant 1.]

Description []

SideEffects []

SeeAlso []

Definition at line 627 of file abcSop.c.

00628 {
00629     return pSop[0] == ' ' && pSop[1] == '1';
00630 }

int Abc_SopIsExorType ( char *  pSop  ) 

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 737 of file abcSop.c.

00738 {
00739     char * pCur;
00740     for ( pCur = pSop; *pCur; pCur++ )
00741         if ( *pCur == '\n' )
00742             return (int)(*(pCur - 1) == 'x' || *(pCur - 1) == 'n');
00743     assert( 0 );
00744     return 0;
00745 }

bool Abc_SopIsInv ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is constant 1.]

Description []

SideEffects []

SeeAlso []

Definition at line 663 of file abcSop.c.

00664 {
00665     if ( pSop[4] != 0 )
00666         return 0;
00667     if ( (pSop[0] == '0' && pSop[2] == '1') || (pSop[0] == '1' && pSop[2] == '0') )
00668         return 1;
00669     return 0;
00670 }

bool Abc_SopIsOrType ( char *  pSop  ) 

Function*************************************************************

Synopsis [Checks if the cover is OR with possibly complemented inputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 707 of file abcSop.c.

00708 {
00709     char * pCube, * pCur;
00710     int nVars, nLits;
00711     nVars = Abc_SopGetVarNum( pSop );
00712     if ( nVars != Abc_SopGetCubeNum(pSop) )
00713         return 0;
00714     Abc_SopForEachCube( pSop, nVars, pCube )
00715     {
00716         // count the number of literals in the cube
00717         nLits = 0;
00718         for ( pCur = pCube; *pCur != ' '; pCur++ )
00719             nLits += ( *pCur != '-' );
00720         if ( nLits != 1 )
00721             return 0;
00722     }
00723     return 1;
00724 }

char* Abc_SopRegister ( Extra_MmFlex_t pMan,
char *  pName 
)

CFile****************************************************************

FileName [abcSop.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Implementation of a simple SOP representation of nodes.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
abcSop.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] DECLARATIONS /// FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Registers the cube string with the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file abcSop.c.

00054 {
00055     char * pRegName;
00056     if ( pName == NULL ) return NULL;
00057     pRegName = Extra_MmFlexEntryFetch( pMan, strlen(pName) + 1 );
00058     strcpy( pRegName, pName );
00059     return pRegName;
00060 }

char* Abc_SopStart ( Extra_MmFlex_t pMan,
int  nCubes,
int  nVars 
)

Function*************************************************************

Synopsis [Creates the constant 1 cover with the given number of variables and cubes.]

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file abcSop.c.

00074 {
00075     char * pSopCover, * pCube;
00076     int i, Length;
00077 
00078     Length = nCubes * (nVars + 3);
00079     pSopCover = Extra_MmFlexEntryFetch( pMan, Length + 1 );
00080     memset( pSopCover, '-', Length );
00081     pSopCover[Length] = 0;
00082 
00083     for ( i = 0; i < nCubes; i++ )
00084     {
00085         pCube = pSopCover + i * (nVars + 3);
00086         pCube[nVars + 0] = ' ';
00087         pCube[nVars + 1] = '1';
00088         pCube[nVars + 2] = '\n';
00089     }
00090     return pSopCover;
00091 }


Generated on Tue Jan 5 12:18:33 2010 for abc70930 by  doxygen 1.6.1