src/base/io/ioReadDsd.c File Reference

#include "io.h"
Include dependency graph for ioReadDsd.c:

Go to the source code of this file.

Functions

char * Io_ReadDsdFindEnd (char *pCur)
int Io_ReadDsdStrSplit (char *pCur, char *pParts[], int *pTypeXor)
Abc_Obj_tIo_ReadDsd_rec (Abc_Ntk_t *pNtk, char *pCur, char *pSop)
Abc_Ntk_tIo_ReadDsd (char *pForm)

Function Documentation

Abc_Ntk_t* Io_ReadDsd ( char *  pForm  ) 

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

Synopsis [Derives the DSD network of the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 229 of file ioReadDsd.c.

00230 {
00231     Abc_Ntk_t * pNtk;
00232     Abc_Obj_t * pObj, * pTop;
00233     Vec_Ptr_t * vNames;
00234     char * pCur, * pFormCopy;
00235     int i, nInputs;
00236 
00237     // count the number of elementary variables
00238     nInputs = 0;
00239     for ( pCur = pForm; *pCur; pCur++ )
00240         if ( *pCur >= 'a' && *pCur <= 'z' )
00241             nInputs = ABC_MAX( nInputs, *pCur - 'a' );
00242     nInputs++;
00243 
00244     // create the network
00245     pNtk = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_SOP, 1 );
00246     pNtk->pName = Extra_UtilStrsav( "dsd" );
00247 
00248     // create PIs
00249     vNames = Abc_NodeGetFakeNames( nInputs );
00250     for ( i = 0; i < nInputs; i++ )
00251         Abc_ObjAssignName( Abc_NtkCreatePi(pNtk), Vec_PtrEntry(vNames, i), NULL );
00252     Abc_NodeFreeNames( vNames );
00253 
00254     // transform the formula by inserting parantheses
00255     // this transforms strings like PRIME(a,b,cd) into (PRIME((a),(b),(cd)))
00256     pCur = pFormCopy = ALLOC( char, 3 * strlen(pForm) + 10 );
00257     *pCur++ = '(';
00258     for ( ; *pForm; pForm++ )
00259         if ( *pForm == '(' )
00260         {
00261             *pCur++ = '(';
00262             *pCur++ = '(';
00263         }
00264         else if ( *pForm == ')' )
00265         {
00266             *pCur++ = ')';
00267             *pCur++ = ')';
00268         }
00269         else if ( *pForm == ',' )
00270         {
00271             *pCur++ = ')';
00272             *pCur++ = ',';
00273             *pCur++ = '(';
00274         }
00275         else
00276             *pCur++ = *pForm;
00277     *pCur++ = ')';
00278     *pCur = 0;
00279 
00280     // parse the formula
00281     pObj = Io_ReadDsd_rec( pNtk, pFormCopy, NULL );
00282     free( pFormCopy );
00283     if ( pObj == NULL )
00284         return NULL;
00285 
00286     // create output
00287     pTop = Abc_NtkCreatePo(pNtk);
00288     Abc_ObjAssignName( pTop, "F", NULL );
00289     Abc_ObjAddFanin( pTop, pObj );
00290 
00291     // create the only PO
00292     if ( !Abc_NtkCheck( pNtk ) )
00293     {
00294         fprintf( stdout, "Io_ReadDsd(): Network check has failed.\n" );
00295         Abc_NtkDelete( pNtk );
00296         return NULL;
00297     }
00298     return pNtk;
00299 }

Abc_Obj_t* Io_ReadDsd_rec ( Abc_Ntk_t pNtk,
char *  pCur,
char *  pSop 
)

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

Synopsis [Recursively parses the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file ioReadDsd.c.

00142 {
00143     Abc_Obj_t * pObj, * pFanin;
00144     char * pEnd, * pParts[32];
00145     int i, nParts, TypeExor;
00146 
00147     // consider complemented formula
00148     if ( *pCur == '!' )
00149     {
00150         pObj = Io_ReadDsd_rec( pNtk, pCur + 1, NULL );
00151         return Abc_NtkCreateNodeInv( pNtk, pObj );
00152     }
00153     if ( *pCur == '(' )
00154     {
00155         assert( pCur[strlen(pCur)-1] == ')' );
00156         pCur[strlen(pCur)-1] = 0;
00157         nParts = Io_ReadDsdStrSplit( pCur+1, pParts, &TypeExor );
00158         if ( nParts == 0 )
00159         {
00160             Abc_NtkDelete( pNtk );
00161             return NULL;
00162         }
00163         pObj = Abc_NtkCreateNode( pNtk );
00164         if ( pSop )
00165         {
00166 //            for ( i = nParts - 1; i >= 0; i-- )
00167             for ( i = 0; i < nParts; i++ )
00168             {
00169                 pFanin = Io_ReadDsd_rec( pNtk, pParts[i], NULL );
00170                 if ( pFanin == NULL )
00171                     return NULL;
00172                 Abc_ObjAddFanin( pObj, pFanin );
00173             }
00174         }
00175         else
00176         {
00177             for ( i = 0; i < nParts; i++ )
00178             {
00179                 pFanin = Io_ReadDsd_rec( pNtk, pParts[i], NULL );
00180                 if ( pFanin == NULL )
00181                     return NULL;
00182                 Abc_ObjAddFanin( pObj, pFanin );
00183             }
00184         }
00185         if ( pSop )
00186             pObj->pData = Abc_SopRegister( pNtk->pManFunc, pSop );
00187         else if ( TypeExor )
00188             pObj->pData = Abc_SopCreateXorSpecial( pNtk->pManFunc, nParts );
00189         else
00190             pObj->pData = Abc_SopCreateAnd( pNtk->pManFunc, nParts, NULL );
00191         return pObj;
00192     }
00193     if ( *pCur >= 'a' && *pCur <= 'z' )
00194     {
00195         assert( *(pCur+1) == 0 );
00196         return Abc_NtkPi( pNtk, *pCur - 'a' );
00197     }
00198 
00199     // skip hex truth table
00200     pEnd = pCur;
00201     while ( (*pEnd >= '0' && *pEnd <= '9') || (*pEnd >= 'A' && *pEnd <= 'F') )
00202         pEnd++;
00203     if ( *pEnd != '(' )
00204     {
00205         printf( "Cannot find the end of hexidecimal truth table.\n" );
00206         return NULL;
00207     }
00208 
00209     // parse the truth table
00210     *pEnd = 0;
00211     pSop = Abc_SopFromTruthHex( pCur );
00212     *pEnd = '(';
00213     pObj = Io_ReadDsd_rec( pNtk, pEnd, pSop );
00214     free( pSop );
00215     return pObj;
00216 }

char* Io_ReadDsdFindEnd ( char *  pCur  ) 

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

FileName [ioReadDsd.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedure to read network from file.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Finds the end of the part.]

Description []

SideEffects []

SeeAlso []

Definition at line 42 of file ioReadDsd.c.

00043 {
00044     char * pEnd;
00045     int nParts = 0;
00046     assert( *pCur == '(' );
00047     for ( pEnd = pCur; *pEnd; pEnd++ )
00048     {
00049         if ( *pEnd == '(' )
00050             nParts++;
00051         else if ( *pEnd == ')' )
00052             nParts--;
00053         if ( nParts == 0 )
00054             return pEnd;
00055     }
00056     return NULL;
00057 }

int Io_ReadDsdStrSplit ( char *  pCur,
char *  pParts[],
int *  pTypeXor 
)

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

Synopsis [Splits the formula into parts.]

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file ioReadDsd.c.

00071 {
00072     int fAnd = 0, fXor = 0, fPri = 0, nParts = 0;
00073     assert( *pCur );
00074     // process the parts
00075     while ( 1 )
00076     {
00077         // save the current part
00078         pParts[nParts++] = pCur;
00079         // skip the complement
00080         if ( *pCur == '!' )
00081             pCur++;
00082         // skip var
00083         if ( *pCur >= 'a' && *pCur <= 'z' )
00084             pCur++;
00085         else
00086         {
00087             // skip hex truth table
00088             while ( (*pCur >= '0' && *pCur <= '9') || (*pCur >= 'A' && *pCur <= 'F') )
00089                 pCur++;
00090             // process parantheses
00091             if ( *pCur != '(' )
00092             {
00093                 printf( "Cannot find the opening paranthesis.\n" );
00094                 break;
00095             }
00096             // find the corresponding closing paranthesis
00097             pCur = Io_ReadDsdFindEnd( pCur );
00098             if ( pCur == NULL )
00099             {
00100                 printf( "Cannot find the closing paranthesis.\n" );
00101                 break;
00102             }
00103             pCur++;
00104         }
00105         // check the end
00106         if ( *pCur == 0 )
00107             break;
00108         // check symbol
00109         if ( *pCur != '*' && *pCur != '+' && *pCur != ',' )
00110         {
00111             printf( "Wrong separating symbol.\n" );
00112             break;
00113         }
00114         // remember the symbol
00115         fAnd |= (*pCur == '*');
00116         fXor |= (*pCur == '+');
00117         fPri |= (*pCur == ',');
00118         *pCur++ = 0;
00119     }
00120     // check separating symbols
00121     if ( fAnd + fXor + fPri > 1 )
00122     {
00123         printf( "Different types of separating symbol ennPartsed.\n" );
00124         return 0;
00125     }
00126     *pTypeXor = fXor;
00127     return nParts;
00128 }


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