34static Mio_Library_t * Mio_LibraryReadOne(
char * FileName,
int fExtendedFormat,
st__table * tExcludeGate,
int nFaninLimit,
int fVerbose );
36static int Mio_LibraryReadInternal(
Mio_Library_t * pLib,
char * pBuffer,
int fExtendedFormat,
st__table * tExcludeGate,
int nFaninLimit,
int fVerbose );
37static Mio_Gate_t * Mio_LibraryReadGate(
char ** ppToken,
int fExtendedFormat );
38static Mio_Pin_t * Mio_LibraryReadPin(
char ** ppToken,
int fExtendedFormat );
39static char * chomp(
char *s );
40static void Mio_LibraryDetectSpecialGates(
Mio_Library_t * pLib );
41static void Io_ReadFileRemoveComments(
char * pBuffer,
int * pnDots,
int * pnLines );
71 fprintf ( stdout,
"Read %d gates from exclude file\n", num );
74 pBufferCopy = Abc_UtilStrsav(pBuffer);
75 if ( pBuffer == NULL )
76 pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, nFaninLimit, fVerbose );
85 if ( pBuffer == NULL )
86 pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, nFaninLimit, fVerbose );
94 printf (
"Warning: Read extended genlib format but ignoring extensions\n" );
100 pLib->
pFileName = Abc_UtilStrsav( FileName );
123 pFile =
Io_FileOpen( FileName,
"open_path",
"rb", 1 );
130 nFileSize = ftell( pFile );
134 pBuffer =
ABC_ALLOC(
char, nFileSize + 10 );
135 RetValue = fread( pBuffer, nFileSize, 1, pFile );
137 pBuffer[ nFileSize ] =
'\0';
139 strcat( pBuffer,
"\n.end\n" );
164 pLib->
vCube = Vec_StrAlloc( 100 );
166 Io_ReadFileRemoveComments( pBuffer, NULL, NULL );
169 if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, nFaninLimit, fVerbose ) )
178 printf(
"Mio_LibraryRead: Had problems parsing formulas.\n" );
184 Mio_LibraryDetectSpecialGates( pLib );
200Mio_Library_t * Mio_LibraryReadOne(
char * FileName,
int fExtendedFormat,
st__table * tExcludeGate,
int nFaninLimit,
int fVerbose )
209 if ( pBuffer == NULL )
214 pLib->
pName = Abc_UtilStrsav( FileName );
229int Mio_LibraryReadInternal(
Mio_Library_t * pLib,
char * pBuffer,
int fExtendedFormat,
st__table * tExcludeGate,
int nFaninLimit,
int fVerbose )
241 pToken =
strtok( pBuffer,
" \t\r\n" );
251 pToken =
strtok( NULL,
" \t\r\n" );
252 printf(
"Skipping latch \"%s\"...\n", pToken );
255 pToken =
strtok( NULL,
" \t\r\n" );
262 pGate = Mio_LibraryReadGate( &pToken, fExtendedFormat );
272 if ( nIns > nFaninLimit )
301 ppGate = &pGate->
pNext;
310 if ( pBase->
pTwin != NULL )
312 printf(
"Gates with more than 2 outputs are not supported.\n" );
315 pBase->
pTwin = pGate;
316 pGate->
pTwin = pBase;
324 printf(
"The library contains no gates.\n" );
329 if ( pToken &&
strcmp( pToken,
".end" ) != 0 )
333 printf(
"Actually excluded %d cells\n", nDel );
352 int whitespace_state = 0;
353 char * pRes = Abc_UtilStrsav(
p );
354 for ( i = k = 0; pRes[i]; i++ )
355 if ( pRes[i] !=
' ' && pRes[i] !=
'\t' && pRes[i] !=
'\r' && pRes[i] !=
'\n' )
357 if ( pRes[i] !=
'(' && pRes[i] !=
')' && pRes[i] !=
'+' && pRes[i] !=
'*' && pRes[i] !=
'|' && pRes[i] !=
'&' && pRes[i] !=
'^' && pRes[i] !=
'\'' && pRes[i] !=
'!' )
359 if (whitespace_state == 2)
361 whitespace_state = 1;
364 whitespace_state = 0;
368 whitespace_state = whitespace_state ? 2 : 0;
373Mio_Gate_t * Mio_LibraryReadGate(
char ** ppToken,
int fExtendedFormat )
377 char * pToken = *ppToken;
384 pToken =
strtok( NULL,
" \t\r\n" );
385 pGate->
pName = Abc_UtilStrsav( pToken );
388 pToken =
strtok( NULL,
" \t\r\n" );
394 pToken =
strtok( NULL,
"=" );
398 pToken =
strtok( NULL,
";" );
400 pGate->
pForm = Abc_UtilStrsav( pToken );
405 ppPin = &pGate->
pPins;
408 pToken =
strtok( NULL,
" \t\r\n" );
412 pPin = Mio_LibraryReadPin( &pToken, fExtendedFormat );
421 ppPin = &pPin->
pNext;
423 pToken =
strtok( NULL,
" \t\r\n" );
443Mio_Pin_t * Mio_LibraryReadPin(
char ** ppToken,
int fExtendedFormat )
446 char * pToken = *ppToken;
452 pToken =
strtok( NULL,
" \t\r\n" );
453 pPin->
pName = Abc_UtilStrsav( pToken );
456 pToken =
strtok( NULL,
" \t\r\n" );
465 printf(
"Cannot read pin phase specification\n" );
471 pToken =
strtok( NULL,
" \t\r\n" );
474 pToken =
strtok( NULL,
" \t\r\n" );
477 pToken =
strtok( NULL,
" \t\r\n" );
480 pToken =
strtok( NULL,
" \t\r\n" );
483 pToken =
strtok( NULL,
" \t\r\n" );
486 pToken =
strtok( NULL,
" \t\r\n" );
489 if ( fExtendedFormat )
497 pToken =
strtok( NULL,
" \t" );
501 pToken =
strtok( NULL,
" \t\r\n" );
526char * chomp(
char *s )
530 for ( b = s; *b; b++ )
536 for ( c = a+
strlen(a); c > a; c-- )
537 if ( *c == 0 || isspace(*c) )
557 double Diff = (*pp1)->dArea - (*pp2)->dArea;
578 int Diff =
strcmp( (*pp1)->pName, (*pp2)->pName );
605 ppGates[i++] = pGate;
610 for ( i = 0; i < pLib->
nGates; i++ )
612 qsort( (
void *)ppGates, (
size_t)pLib->
nGates,
sizeof(
void *),
614 for ( i = 0; i < pLib->
nGates; i++ )
615 ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL;
616 pLib->
pGates = ppGates[0];
633 if ( pNew->
uTruth != uTruth )
644 word uFuncBuf, uFuncInv, uFuncNand2, uFuncAnd2, uFuncNor2, uFuncOr2;
648 uFuncBuf =
ABC_CONST(0xAAAAAAAAAAAAAAAA);
651 uFuncInv = ~uFuncBuf;
652 uFuncNand2 = ~uFuncAnd2;
653 uFuncNor2 = ~uFuncOr2;
660 printf(
"Warnings: genlib library reader cannot detect the buffer gate.\n" );
661 printf(
"Some parts of the supergate-based technology mapper may not work correctly.\n" );
669 printf(
"Warnings: genlib library reader cannot detect the invertor gate.\n" );
670 printf(
"Some parts of the supergate-based technology mapper may not work correctly.\n" );
683 printf(
"Warnings: genlib library reader cannot detect the AND2, NAND2, OR2, and NOR2 gate.\n" );
684 printf(
"Some parts of the supergate-based technology mapper may not work correctly.\n" );
709 pEx = fopen( ExcludeFile,
"r" );
713 fprintf ( stdout,
"Error: Could not open exclude file %s. Stop.\n", ExcludeFile );
717 while (1 == fscanf( pEx,
"%127s", buffer ))
720 st__insert( tExcludeGate, Abc_UtilStrsav( buffer ), (
char *)0 );
743void Io_ReadFileRemoveComments(
char * pBuffer,
int * pnDots,
int * pnLines )
750 for ( pCur = pBuffer; *pCur; pCur++ )
754 if ( *pCur ==
'#' ) {
755 while ( *pCur !=
'\n' ) {
760 if ( *pCur ==
'\n' ) {
761 if (pCur > pBuffer) {
762 if (*(pCur - 1) ==
'\r') {
764 if (pCur > (pBuffer + 1)) {
765 if (*(pCur - 2) !=
'\\') {
777 if (*(pCur - 1) !=
'\\') {
788 else if ( *pCur ==
'.' ) {
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
FILE * Io_FileOpen(const char *FileName, const char *PathVar, const char *Mode, int fVerbose)
unsigned __int64 word
DECLARATIONS ///.
Mem_Flex_t * Mem_FlexStart()
#define MIO_STRING_UNKNOWN
#define MIO_STRING_GATE
INCLUDES ///.
#define MIO_STRING_NONINV
char * Mio_LibraryCleanStr(char *p)
void Mio_LibrarySortGates(Mio_Library_t *pLib)
Mio_Library_t * Mio_LibraryReadBuffer(char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int nFaninLimit, int fVerbose)
int Mio_LibraryCompareGatesByArea(Mio_Gate_t **pp1, Mio_Gate_t **pp2)
int Mio_LibraryCompareGatesByName(Mio_Gate_t **pp1, Mio_Gate_t **pp2)
char * Mio_ReadFile(char *FileName, int fAddEnd)
Mio_Library_t * Mio_LibraryRead(char *FileName, char *pBuffer, char *ExcludeFile, int nFaninLimit, int fVerbose)
int Mio_LibraryReadExclude(char *ExcludeFile, st__table *tExcludeGate)
Mio_Pin_t * Mio_GateReadPins(Mio_Gate_t *pGate)
int Mio_ParseCheckFormula(Mio_Gate_t *pGate, char *pForm)
struct Mio_LibraryStruct_t_ Mio_Library_t
void Mio_LibraryDelete(Mio_Library_t *pLib)
DECLARATIONS ///.
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
void Mio_PinDelete(Mio_Pin_t *pPin)
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Mio_Pin_t * Mio_PinReadNext(Mio_Pin_t *pPin)
struct Mio_PinStruct_t_ Mio_Pin_t
void Mio_GateDelete(Mio_Gate_t *pGate)
struct Mio_GateStruct_t_ Mio_Gate_t
int Mio_LibraryParseFormulas(Mio_Library_t *pLib)
FUNCTION DEFINITIONS ///.
int st__strhash(const char *string, int modulus)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
int st__insert(st__table *table, const char *key, char *value)
void st__free_table(st__table *table)
#define st__is_member(table, key)
Mio_Gate_t ** ppGatesName