summaryrefslogtreecommitdiffstats
path: root/src/aig/gia
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2011-04-17 19:11:57 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2011-04-17 19:11:57 -0700
commit7bcd5ac979fc14101a6eb9ee34940f272009c67f (patch)
treef14f6d757ab85ee69b79aac581cd9b90504c6c78 /src/aig/gia
parent0aefe77ea5dd0ac6a3773675a379aa2e592f82cc (diff)
downloadabc-7bcd5ac979fc14101a6eb9ee34940f272009c67f.tar.gz
abc-7bcd5ac979fc14101a6eb9ee34940f272009c67f.tar.bz2
abc-7bcd5ac979fc14101a6eb9ee34940f272009c67f.zip
Changes to incorporate AIG parsing in memory and user-specified PI/PO/FF numbers.
Diffstat (limited to 'src/aig/gia')
-rw-r--r--src/aig/gia/gia.h6
-rw-r--r--src/aig/gia/giaAbs.c4
-rw-r--r--src/aig/gia/giaAiger.c300
-rw-r--r--src/aig/gia/giaMan.c5
4 files changed, 308 insertions, 7 deletions
diff --git a/src/aig/gia/gia.h b/src/aig/gia/gia.h
index 16259a1e..d0c12618 100644
--- a/src/aig/gia/gia.h
+++ b/src/aig/gia/gia.h
@@ -138,8 +138,9 @@ struct Gia_Man_t_
int nTravIdsAlloc; // the number of trav IDs allocated
Vec_Ptr_t * vNamesIn; // the input names
Vec_Ptr_t * vNamesOut; // the output names
- Vec_Int_t * vCiNumsOrig; // original names of the CIs
- Vec_Int_t * vCoNumsOrig; // original names of the COs
+ Vec_Int_t * vUserPiIds; // numbers assigned to PIs by the user
+ Vec_Int_t * vUserPoIds; // numbers assigned to POs by the user
+ Vec_Int_t * vUserFfIds; // numbers assigned to FFs by the user
Vec_Vec_t * vClockDoms; // clock domains
Vec_Flt_t * vTiming; // arrival/required/slack
void * pManTime; // the timing manager
@@ -596,6 +597,7 @@ static inline int Gia_ObjLutFanin( Gia_Man_t * p, int Id, int i ) { re
/*=== giaAiger.c ===========================================================*/
extern int Gia_FileSize( char * pFileName );
+extern Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck );
extern Gia_Man_t * Gia_ReadAiger( char * pFileName, int fCheck );
extern void Gia_WriteAiger( Gia_Man_t * p, char * pFileName, int fWriteSymbols, int fCompact );
extern void Gia_DumpAiger( Gia_Man_t * p, char * pFilePrefix, int iFileNum, int nFileNumDigits );
diff --git a/src/aig/gia/giaAbs.c b/src/aig/gia/giaAbs.c
index d31e62f5..7c20851d 100644
--- a/src/aig/gia/giaAbs.c
+++ b/src/aig/gia/giaAbs.c
@@ -138,8 +138,8 @@ Gia_Man_t * Gia_ManCexAbstraction( Gia_Man_t * p, Vec_Int_t * vFlops )
pNew = Saig_ManDeriveAbstraction( pTemp = pNew, vFlops );
Aig_ManStop( pTemp );
pGia = Gia_ManFromAig( pNew );
- pGia->vCiNumsOrig = pNew->vCiNumsOrig;
- pNew->vCiNumsOrig = NULL;
+// pGia->vCiNumsOrig = pNew->vCiNumsOrig;
+// pNew->vCiNumsOrig = NULL;
Aig_ManStop( pNew );
return pGia;
diff --git a/src/aig/gia/giaAiger.c b/src/aig/gia/giaAiger.c
index 14a2769e..5674ff8c 100644
--- a/src/aig/gia/giaAiger.c
+++ b/src/aig/gia/giaAiger.c
@@ -342,7 +342,7 @@ Gia_Plc_t * Gia_ReadPlacement( unsigned char ** ppPos, int nSize )
SeeAlso []
***********************************************************************/
-Gia_Man_t * Gia_ReadAiger( char * pFileName, int fCheck )
+Gia_Man_t * Gia_ReadAiger2( char * pFileName, int fCheck )
{
FILE * pFile;
Gia_Man_t * pNew;
@@ -558,6 +558,304 @@ Gia_Man_t * Gia_ReadAiger( char * pFileName, int fCheck )
/**Function*************************************************************
+ Synopsis [Reads the AIG in the binary AIGER format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck )
+{
+ Gia_Man_t * pNew;
+ Vec_Int_t * vLits = NULL;
+ Vec_Int_t * vNodes, * vDrivers;//, * vTerms;
+ int iObj, iNode0, iNode1;
+ int nTotal, nInputs, nOutputs, nLatches, nAnds, i;//, iTerm, nDigits;
+ unsigned char * pDrivers, * pSymbols, * pCur;//, * pType;
+ unsigned uLit0, uLit1, uLit;
+
+ // read the file type
+ pCur = (unsigned char *)pContents; while ( *pCur++ != ' ' );
+ // read the number of objects
+ nTotal = atoi( (char *)pCur ); while ( *pCur++ != ' ' );
+ // read the number of inputs
+ nInputs = atoi( (char *)pCur ); while ( *pCur++ != ' ' );
+ // read the number of latches
+ nLatches = atoi( (char *)pCur ); while ( *pCur++ != ' ' );
+ // read the number of outputs
+ nOutputs = atoi( (char *)pCur ); while ( *pCur++ != ' ' );
+ // read the number of nodes
+ nAnds = atoi( (char *)pCur ); while ( *pCur++ != '\n' );
+ // check the parameters
+ if ( nTotal != nInputs + nLatches + nAnds )
+ {
+ ABC_FREE( pContents );
+ fprintf( stdout, "The paramters are wrong.\n" );
+ return NULL;
+ }
+
+ // allocate the empty AIG
+ pNew = Gia_ManStart( nTotal + nLatches + nOutputs + 1 );
+
+ // prepare the array of nodes
+ vNodes = Vec_IntAlloc( 1 + nTotal );
+ Vec_IntPush( vNodes, 0 );
+
+ // create the PIs
+ for ( i = 0; i < nInputs + nLatches; i++ )
+ {
+ iObj = Gia_ManAppendCi(pNew);
+ Vec_IntPush( vNodes, iObj );
+ }
+
+ // remember the beginning of latch/PO literals
+ pDrivers = pCur;
+ if ( pContents[3] == ' ' ) // standard AIGER
+ {
+ // scroll to the beginning of the binary data
+ for ( i = 0; i < nLatches + nOutputs; )
+ if ( *pCur++ == '\n' )
+ i++;
+ }
+ else // modified AIGER
+ {
+ vLits = Gia_WriteDecodeLiterals( &pCur, nLatches + nOutputs );
+ }
+
+ // create the AND gates
+ for ( i = 0; i < nAnds; i++ )
+ {
+ uLit = ((i + 1 + nInputs + nLatches) << 1);
+ uLit1 = uLit - Gia_ReadAigerDecode( &pCur );
+ uLit0 = uLit1 - Gia_ReadAigerDecode( &pCur );
+// assert( uLit1 > uLit0 );
+ iNode0 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), uLit0 & 1 );
+ iNode1 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit1 >> 1), uLit1 & 1 );
+ assert( Vec_IntSize(vNodes) == i + 1 + nInputs + nLatches );
+// Vec_IntPush( vNodes, Gia_And(pNew, iNode0, iNode1) );
+ Vec_IntPush( vNodes, Gia_ManAppendAnd(pNew, iNode0, iNode1) );
+ }
+
+ // remember the place where symbols begin
+ pSymbols = pCur;
+
+ // read the latch driver literals
+ vDrivers = Vec_IntAlloc( nLatches + nOutputs );
+ if ( pContents[3] == ' ' ) // standard AIGER
+ {
+ pCur = pDrivers;
+ for ( i = 0; i < nLatches; i++ )
+ {
+ uLit0 = atoi( (char *)pCur ); while ( *pCur++ != '\n' );
+ iNode0 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
+ Vec_IntPush( vDrivers, iNode0 );
+ }
+ // read the PO driver literals
+ for ( i = 0; i < nOutputs; i++ )
+ {
+ uLit0 = atoi( (char *)pCur ); while ( *pCur++ != '\n' );
+ iNode0 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
+ Vec_IntPush( vDrivers, iNode0 );
+ }
+
+ }
+ else
+ {
+ // read the latch driver literals
+ for ( i = 0; i < nLatches; i++ )
+ {
+ uLit0 = Vec_IntEntry( vLits, i );
+ iNode0 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
+ Vec_IntPush( vDrivers, iNode0 );
+ }
+ // read the PO driver literals
+ for ( i = 0; i < nOutputs; i++ )
+ {
+ uLit0 = Vec_IntEntry( vLits, i+nLatches );
+ iNode0 = Gia_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
+ Vec_IntPush( vDrivers, iNode0 );
+ }
+ Vec_IntFree( vLits );
+ }
+
+ // create the POs
+ for ( i = 0; i < nOutputs; i++ )
+ Gia_ManAppendCo( pNew, Vec_IntEntry(vDrivers, nLatches + i) );
+ for ( i = 0; i < nLatches; i++ )
+ Gia_ManAppendCo( pNew, Vec_IntEntry(vDrivers, i) );
+ Vec_IntFree( vDrivers );
+
+ // create the latches
+ Gia_ManSetRegNum( pNew, nLatches );
+
+ // check if there are other types of information to read
+ pCur = pSymbols;
+ if ( (char *)pCur + 1 < pContents + nFileSize && *pCur == 'c' )
+ {
+ pCur++;
+ if ( *pCur == 'e' )
+ {
+ pCur++;
+ // read equivalence classes
+ pNew->pReprs = Gia_ReadEquivClasses( &pCur, Gia_ManObjNum(pNew) );
+ pNew->pNexts = Gia_ManDeriveNexts( pNew );
+ }
+ if ( *pCur == 'f' )
+ {
+ pCur++;
+ // read flop classes
+ pNew->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) );
+ Gia_ReadFlopClasses( &pCur, pNew->vFlopClasses, Gia_ManRegNum(pNew) );
+ }
+ if ( *pCur == 'm' )
+ {
+ pCur++;
+ // read mapping
+ pNew->pMapping = Gia_ReadMapping( &pCur, Gia_ManObjNum(pNew) );
+ }
+ if ( *pCur == 'p' )
+ {
+ pCur++;
+ // read placement
+ pNew->pPlacement = Gia_ReadPlacement( &pCur, Gia_ManObjNum(pNew) );
+ }
+ if ( *pCur == 's' )
+ {
+ pCur++;
+ // read switching activity
+ pNew->pSwitching = Gia_ReadSwitching( &pCur, Gia_ManObjNum(pNew) );
+ }
+ if ( *pCur == 'c' )
+ {
+ pCur++;
+ // read number of constraints
+ pNew->nConstrs = Gia_ReadInt( pCur ); pCur += 4;
+ }
+ if ( *pCur == 'n' )
+ {
+ pCur++;
+ // read model name
+ ABC_FREE( pNew->pName );
+ pNew->pName = Gia_UtilStrsav( (char *)pCur );
+ }
+ }
+
+ // read signal names if they are of the special type
+ if ( *pCur != 'c' )
+ {
+ int fBreakUsed = 0;
+ pNew->vUserPiIds = Vec_IntStartFull( Gia_ManPiNum(pNew) );
+ pNew->vUserPoIds = Vec_IntStartFull( Gia_ManPoNum(pNew) );
+ pNew->vUserFfIds = Vec_IntStartFull( Gia_ManRegNum(pNew) );
+ while ( pCur < pContents + nFileSize && *pCur != 'c' )
+ {
+ int iTerm;
+ char * pType = pCur;
+ // check terminal type
+ if ( *pCur != 'i' && *pCur != 'o' && *pCur != 'l' )
+ {
+ fprintf( stdout, "Wrong terminal type.\n" );
+ fBreakUsed = 1;
+ break;
+ }
+ // get terminal number
+ iTerm = atoi( ++pCur ); while ( *pCur++ != ' ' );
+ // skip spaces
+ while ( *pCur++ == ' ' );
+ // decode the user numbers:
+ // flops are named: @l<num>
+ // PIs are named: @i<num>
+ // POs are named: @o<num>
+ if ( *pCur++ != '@' )
+ {
+ fBreakUsed = 1;
+ break;
+ }
+ if ( *pCur == 'i' && *pType == 'i' )
+ Vec_IntWriteEntry( pNew->vUserPiIds, iTerm, atoi(pCur+1) );
+ else if ( *pCur == 'o' && *pType == 'o' )
+ Vec_IntWriteEntry( pNew->vUserPoIds, iTerm, atoi(pCur+1) );
+ else if ( *pCur == 'l' && *pType == 'l' )
+ Vec_IntWriteEntry( pNew->vUserFfIds, iTerm, atoi(pCur+1) );
+ else
+ {
+ fprintf( stdout, "Wrong name format.\n" );
+ fBreakUsed = 1;
+ break;
+ }
+ // skip digits
+ while ( *pCur++ != '\n' );
+ }
+ // in case of abnormal termination, remove the arrays
+ if ( fBreakUsed )
+ {
+ Vec_IntFreeP( &pNew->vUserPiIds );
+ Vec_IntFreeP( &pNew->vUserPoIds );
+ Vec_IntFreeP( &pNew->vUserFfIds );
+ }
+ }
+
+
+ // skipping the comments
+ ABC_FREE( pContents );
+ Vec_IntFree( vNodes );
+/*
+ // check the result
+ if ( fCheck && !Gia_ManCheck( pNew ) )
+ {
+ printf( "Gia_ReadAiger: The network check has failed.\n" );
+ Gia_ManStop( pNew );
+ return NULL;
+ }
+*/
+ return pNew;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads the AIG in the binary AIGER format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Gia_Man_t * Gia_ReadAiger( char * pFileName, int fCheck )
+{
+ FILE * pFile;
+ Gia_Man_t * pNew;
+ char * pName, * pContents;
+ int nFileSize;
+
+ // read the file into the buffer
+ Gia_FixFileName( pFileName );
+ nFileSize = Gia_FileSize( pFileName );
+ pFile = fopen( pFileName, "rb" );
+ pContents = ABC_ALLOC( char, nFileSize );
+ fread( pContents, nFileSize, 1, pFile );
+ fclose( pFile );
+
+ pNew = Gia_ReadAigerFromMemory( pContents, nFileSize, fCheck );
+ ABC_FREE( pContents );
+ if ( pNew )
+ {
+ pName = Gia_FileNameGeneric( pFileName );
+ pNew->pName = Gia_UtilStrsav( pName );
+// pNew->pSpec = Ioa_UtilStrsav( pFileName );
+ ABC_FREE( pName );
+ }
+ return pNew;
+}
+
+
+
+/**Function*************************************************************
+
Synopsis [Adds one unsigned AIG edge to the output buffer.]
Description [This procedure is a slightly modified version of Armin Biere's
diff --git a/src/aig/gia/giaMan.c b/src/aig/gia/giaMan.c
index ed6a5c95..dc0f926c 100644
--- a/src/aig/gia/giaMan.c
+++ b/src/aig/gia/giaMan.c
@@ -77,8 +77,9 @@ void Gia_ManStop( Gia_Man_t * p )
Vec_FltFreeP( &p->vTiming );
Vec_VecFreeP( &p->vClockDoms );
Vec_IntFreeP( &p->vLutConfigs );
- Vec_IntFreeP( &p->vCiNumsOrig );
- Vec_IntFreeP( &p->vCoNumsOrig );
+ Vec_IntFreeP( &p->vUserPiIds );
+ Vec_IntFreeP( &p->vUserPoIds );
+ Vec_IntFreeP( &p->vUserFfIds );
Vec_IntFreeP( &p->vFlopClasses );
Vec_IntFreeP( &p->vLevels );
Vec_IntFreeP( &p->vTruths );