New parser and framework.

This commit is contained in:
Alan Mishchenko
2014-11-29 14:36:26 -08:00
parent c30a0ca0b9
commit 24f1ca0703
24 changed files with 3294 additions and 837 deletions
+1
View File
@@ -106,6 +106,7 @@ extern char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix );
extern void Extra_FileNameCorrectPath( char * FileName );
extern char * Extra_FileNameWithoutPath( char * FileName );
extern char * Extra_FilePathWithoutName( char * FileName );
extern char * Extra_FileDesignName( char * pFileName );
extern int Extra_FileCheck( char * pFileName );
extern int Extra_FileSize( char * pFileName );
extern char * Extra_FileRead( FILE * pFile );
+19
View File
@@ -247,6 +247,25 @@ char * Extra_FilePathWithoutName( char * FileName )
ABC_FREE( FileName );
return NULL;
}
char * Extra_FileDesignName( char * pFileName )
{
char * pBeg, * pEnd, * pStore, * pCur;
// find the first dot
for ( pEnd = pFileName; *pEnd; pEnd++ )
if ( *pEnd == '.' )
break;
// find the first char
for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
break;
pBeg++;
// fill up storage
pStore = ABC_ALLOC( char, pEnd - pBeg + 1 );
for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
*pCur = *pBeg;
*pCur = 0;
return pStore;
}
/**Function*************************************************************
+62 -12
View File
@@ -237,7 +237,7 @@ int Abc_NamMemAlloc( Abc_Nam_t * p )
SeeAlso []
***********************************************************************/
int Abc_NamStrHash( const char * pStr, int nTableSize )
int Abc_NamStrHash( const char * pStr, const char * pLim, int nTableSize )
{
static int s_FPrimes[128] = {
1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
@@ -255,11 +255,22 @@ int Abc_NamStrHash( const char * pStr, int nTableSize )
8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
};
unsigned i, uHash;
for ( uHash = 0, i = 0; pStr[i]; i++ )
if ( i & 1 )
uHash *= pStr[i] * s_FPrimes[i & 0x7F];
else
uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
if ( pLim )
{
for ( uHash = 0, i = 0; pStr < pLim; i++ )
if ( i & 1 )
uHash *= pStr[i] * s_FPrimes[i & 0x7F];
else
uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
}
else
{
for ( uHash = 0, i = 0; pStr[i]; i++ )
if ( i & 1 )
uHash *= pStr[i] * s_FPrimes[i & 0x7F];
else
uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
}
return uHash % nTableSize;
}
@@ -274,10 +285,10 @@ int Abc_NamStrHash( const char * pStr, int nTableSize )
SeeAlso []
***********************************************************************/
static inline int * Abc_NamStrHashFind( Abc_Nam_t * p, const char * pStr )
static inline int * Abc_NamStrHashFind( Abc_Nam_t * p, const char * pStr, const char * pLim )
{
char * pThis;
int * pPlace = (int *)(p->pBins + Abc_NamStrHash( pStr, p->nBins ));
int * pPlace = (int *)(p->pBins + Abc_NamStrHash( pStr, pLim, p->nBins ));
assert( *pStr );
for ( pThis = (*pPlace)? Abc_NamIntToStr(p, *pPlace) : NULL;
pThis; pPlace = Abc_NamIntToNextP(p, *pPlace),
@@ -318,7 +329,7 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
Vec_IntForEachEntryStart( vInt2HandleOld, iHandleOld, i, 1 )
{
pThis = Abc_NamHandleToStr( p, iHandleOld );
piPlace = Abc_NamStrHashFind( p, pThis );
piPlace = Abc_NamStrHashFind( p, pThis, NULL );
assert( *piPlace == 0 );
*piPlace = Vec_IntSize( p->vInt2Handle );
assert( Vec_IntSize( p->vInt2Handle ) == i );
@@ -343,7 +354,11 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
***********************************************************************/
int Abc_NamStrFind( Abc_Nam_t * p, char * pStr )
{
return *Abc_NamStrHashFind( p, pStr );
return *Abc_NamStrHashFind( p, pStr, NULL );
}
int Abc_NamStrFindLim( Abc_Nam_t * p, char * pStr, char * pLim )
{
return *Abc_NamStrHashFind( p, pStr, pLim );
}
/**Function*************************************************************
@@ -368,7 +383,7 @@ int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound )
break;
assert( i < (int)strlen(pStr) );
}
piPlace = Abc_NamStrHashFind( p, pStr );
piPlace = Abc_NamStrHashFind( p, pStr, NULL );
if ( *piPlace )
{
if ( pfFound )
@@ -396,6 +411,41 @@ int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound )
Abc_NamStrHashResize( p );
return Vec_IntSize(p->vInt2Handle) - 1;
}
int Abc_NamStrFindOrAddLim( Abc_Nam_t * p, char * pStr, char * pLim, int * pfFound )
{
int iHandleNew;
int *piPlace;
char * pStore;
piPlace = Abc_NamStrHashFind( p, pStr, pLim );
if ( *piPlace )
{
if ( pfFound )
*pfFound = 1;
return *piPlace;
}
if ( pfFound )
*pfFound = 0;
iHandleNew = p->iHandle + (pLim - pStr) + 1;
while ( p->nStore < iHandleNew )
{
p->nStore *= 3;
p->nStore /= 2;
p->pStore = ABC_REALLOC( char, p->pStore, p->nStore );
}
assert( p->nStore >= iHandleNew );
// create new handle
*piPlace = Vec_IntSize( p->vInt2Handle );
pStore = Abc_NamHandleToStr( p, p->iHandle );
strncpy( pStore, pStr, pLim - pStr );
pStore[pLim - pStr] = 0;
Vec_IntPush( p->vInt2Handle, p->iHandle );
Vec_IntPush( p->vInt2Next, 0 );
p->iHandle = iHandleNew;
// extend the hash table
if ( Vec_IntSize(p->vInt2Handle) > 2 * p->nBins )
Abc_NamStrHashResize( p );
return Vec_IntSize(p->vInt2Handle) - 1;
}
/**Function*************************************************************
@@ -435,7 +485,7 @@ Vec_Int_t * Abc_NamComputeIdMap( Abc_Nam_t * p1, Abc_Nam_t * p2 )
Vec_IntForEachEntryStart( p1->vInt2Handle, iHandle1, i, 1 )
{
pThis = Abc_NamHandleToStr( p1, iHandle1 );
piPlace = Abc_NamStrHashFind( p2, pThis );
piPlace = Abc_NamStrHashFind( p2, pThis, NULL );
Vec_IntWriteEntry( vMap, i, *piPlace );
// Abc_Print( 1, "%d->%d ", i, *piPlace );
}
+2
View File
@@ -59,7 +59,9 @@ extern int Abc_NamObjNumMax( Abc_Nam_t * p );
extern int Abc_NamMemUsed( Abc_Nam_t * p );
extern int Abc_NamMemAlloc( Abc_Nam_t * p );
extern int Abc_NamStrFind( Abc_Nam_t * p, char * pStr );
extern int Abc_NamStrFindLim( Abc_Nam_t * p, char * pStr, char * pLim );
extern int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound );
extern int Abc_NamStrFindOrAddLim( Abc_Nam_t * p, char * pStr, char * pLim, int * pfFound );
extern char * Abc_NamStr( Abc_Nam_t * p, int id );
extern Vec_Int_t * Abc_NamComputeIdMap( Abc_Nam_t * p1, Abc_Nam_t * p2 );
extern int Abc_NamReportCommon( Vec_Int_t * vNameIds1, Abc_Nam_t * p1, Abc_Nam_t * p2 );
+42
View File
@@ -65,6 +65,8 @@ struct Vec_Int_t_
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
#define Vec_IntForEachEntryTriple( vVec, Entry1, Entry2, Entry3, i ) \
for ( i = 0; (i+2 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1) && (((Entry3) = Vec_IntEntry(vVec, i+2)), 1); i += 3 )
#define Vec_IntForEachEntryThisNext( vVec, This, Next, i ) \
for ( i = 0, (This) = (Next) = (Vec_IntSize(vVec) ? Vec_IntEntry(vVec, 0) : -1); (i+1 < Vec_IntSize(vVec)) && (((Next) = Vec_IntEntry(vVec, i+1)), 1); i += 2, (This) = (Next) )
@@ -696,6 +698,11 @@ static inline void Vec_IntPush( Vec_Int_t * p, int Entry )
}
p->pArray[p->nSize++] = Entry;
}
static inline void Vec_IntPushTwo( Vec_Int_t * p, int Entry1, int Entry2 )
{
Vec_IntPush( p, Entry1 );
Vec_IntPush( p, Entry2 );
}
static inline void Vec_IntPushArray( Vec_Int_t * p, int * pEntries, int nEntries )
{
int i;
@@ -1043,6 +1050,34 @@ static inline void Vec_IntReverseOrder( Vec_Int_t * p )
}
}
/**Function*************************************************************
Synopsis [Removes odd entries.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Vec_IntRemoveOdd( Vec_Int_t * p )
{
int i;
assert( (p->nSize & 1) == 0 );
p->nSize >>= 1;
for ( i = 0; i < p->nSize; i++ )
p->pArray[i] = p->pArray[2*i];
}
static inline void Vec_IntRemoveEven( Vec_Int_t * p )
{
int i;
assert( (p->nSize & 1) == 0 );
p->nSize >>= 1;
for ( i = 0; i < p->nSize; i++ )
p->pArray[i] = p->pArray[2*i+1];
}
/**Function*************************************************************
Synopsis []
@@ -1144,6 +1179,13 @@ static inline int Vec_IntCountPositive( Vec_Int_t * p )
Counter += (p->pArray[i] > 0);
return Counter;
}
static inline int Vec_IntCountZero( Vec_Int_t * p )
{
int i, Counter = 0;
for ( i = 0; i < p->nSize; i++ )
Counter += (p->pArray[i] == 0);
return Counter;
}
/**Function*************************************************************