30#define ABC_MAX_LIB_STR_LEN 5000
75static inline void Amap_PrintWord( FILE * pFile,
Amap_Tree_t *
p,
Amap_Pair_t Pair ) {
char * pBeg =
p->pContents+Pair.
Beg, * pEnd =
p->pContents+Pair.
End;
while ( pBeg < pEnd ) fputc( *pBeg++, pFile ); }
76static inline void Amap_PrintSpace( FILE * pFile,
int nOffset ) {
int i;
for ( i = 0; i < nOffset; i++ ) fputc(
' ', pFile); }
79#define Amap_ItemForEachChild( p, pItem, pChild ) \
80 for ( pChild = Amap_LibertyItem(p, pItem->Child); pChild; pChild = Amap_LibertyItem(p, pChild->Next) )
101 Amap_PrintSpace( pFile, nOffset );
102 Amap_PrintWord( pFile,
p, pItem->
Key );
103 fprintf( pFile,
"(" );
104 Amap_PrintWord( pFile,
p, pItem->
Head );
105 fprintf( pFile,
") {\n" );
106 if ( Amap_LibertyItem(
p, pItem->
Child) )
108 Amap_PrintSpace( pFile, nOffset );
109 fprintf( pFile,
"}\n" );
113 Amap_PrintSpace( pFile, nOffset );
114 Amap_PrintWord( pFile,
p, pItem->
Key );
115 fprintf( pFile,
" : " );
116 Amap_PrintWord( pFile,
p, pItem->
Head );
117 fprintf( pFile,
";\n" );
121 Amap_PrintSpace( pFile, nOffset );
122 Amap_PrintWord( pFile,
p, pItem->
Key );
123 fprintf( pFile,
"(" );
124 Amap_PrintWord( pFile,
p, pItem->
Head );
125 fprintf( pFile,
");\n" );
128 if ( Amap_LibertyItem(
p, pItem->
Next) )
146 if ( pFileName == NULL )
150 pFile = fopen( pFileName,
"w" );
153 printf(
"Amap_LibertyPrintLiberty(): The output file is unavailable (absent or open).\n" );
158 if ( pFile != stdout )
177 static char Buffer[100];
182 TimeStamp = asctime( localtime( <ime ) );
183 TimeStamp[
strlen(TimeStamp) - 1 ] = 0;
185 strcpy( Buffer, TimeStamp );
204 if ( !Amap_LibertyCompare(
p, pAttr->
Key,
"ff") ||
205 !Amap_LibertyCompare(
p, pAttr->
Key,
"latch") )
225 if ( !Amap_LibertyCompare(
p, pAttr->
Key,
"dont_use") )
245 if ( !Amap_LibertyCompare(
p, pFunc->
Key,
"function") )
266 if ( Amap_LibertyCompare(
p, pPin->
Key,
"pin") )
277 vOutPins = Vec_PtrAlloc( 2 );
280 if ( Amap_LibertyCompare(
p, pPin->
Key,
"pin") )
283 Vec_PtrPush( vOutPins, pPin );
304 if ( Amap_LibertyCompare(
p, pArea->
Key,
"area") )
328 if ( Amap_LibertyCompare(
p, pPin->
Key,
"pin") )
352 Buffer[Pair.
End-Pair.
Beg] = 0;
372 Buffer[Pair.
End-Pair.
Beg-2] = 0;
391 Amap_Item_t * pCell, * pArea, * pFunc, * pPin, * pOutput;
394 if ( pFileName == NULL )
398 pFile = fopen( pFileName,
"w" );
401 printf(
"Amap_LibertyPrintGenlib(): The output file is unavailable (absent or open).\n" );
406 fprintf( pFile,
"# The standard cell library \"%s\" is from Liberty file \"%s\"\n",
Amap_LibertyGetString(
p, Amap_LibertyRoot(
p)->Head),
p->pFileName );
407 fprintf( pFile,
"# (To find out more about Genlib format, google for \"sis_paper.ps\")\n" );
409 fprintf( pFile,
"GATE " );
410 fprintf( pFile,
"%16s ",
"_const0_" );
411 fprintf( pFile,
"%f ", 0.0 );
412 fprintf( pFile,
"%s=",
"z" );
413 fprintf( pFile,
"%s;\n",
"CONST0" );
415 fprintf( pFile,
"GATE " );
416 fprintf( pFile,
"%16s ",
"_const1_" );
417 fprintf( pFile,
"%f ", 0.0 );
418 fprintf( pFile,
"%s=",
"z" );
419 fprintf( pFile,
"%s;\n",
"CONST1" );
429 if ( Amap_LibertyCompare(
p, pCell->
Key,
"cell") )
440 printf(
"Amap_LibertyPrintGenlib() skipped cell \"%s\" due to dont_use attribute.\n",
Amap_LibertyGetString(
p, pCell->
Head) );
474 printf(
"Amap_LibertyPrintGenlib() skipped cell \"%s\" with constant formula \"%s\".\n",
Amap_LibertyGetString(
p, pCell->
Head), pForm );
477 fprintf( pFile,
"GATE " );
483 if ( Vec_PtrFind(vOutputs, pPin) == -1 && !Amap_LibertyCompare(
p, pPin->
Key,
"pin") )
486 Vec_PtrFree( vOutputs );
488 if ( pFile != stdout )
509 Amap_Item_t * pCell, * pArea, * pFunc, * pPin, * pOutput;
513 vStr = Vec_StrAlloc( 1000 );
515 Vec_StrPrintStr( vStr,
"GATE _const0_ 0.000000 z=CONST0;\n" );
516 Vec_StrPrintStr( vStr,
"GATE _const1_ 0.000000 z=CONST1;\n" );
519 if ( Amap_LibertyCompare(
p, pCell->
Key,
"cell") )
530 printf(
"Amap_LibertyPrintGenlib() skipped cell \"%s\" due to dont_use attribute.\n",
Amap_LibertyGetString(
p, pCell->
Head) );
555 printf(
"Amap_LibertyPrintGenlib() skipped cell \"%s\" with constant formula \"%s\".\n",
Amap_LibertyGetString(
p, pCell->
Head), pForm );
568 Vec_StrPrintStr( vStr,
"GATE " );
570 Vec_StrPrintStr( vStr,
" " );
572 Vec_StrPrintStr( vStr, Buffer );
573 Vec_StrPrintStr( vStr,
" " );
575 Vec_StrPrintStr( vStr,
"=" );
577 Vec_StrPrintStr( vStr,
";\n" );
579 if ( Vec_PtrFind(vOutputs, pPin) == -1 && !Amap_LibertyCompare(
p, pPin->
Key,
"pin") )
581 Vec_StrPrintStr( vStr,
" PIN " );
583 Vec_StrPrintStr( vStr,
" UNKNOWN 1 999 1.00 0.00 1.00 0.00\n" );
586 Vec_PtrFree( vOutputs );
588 Vec_StrPrintStr( vStr,
"\n.end\n" );
589 Vec_StrPush( vStr,
'\0' );
610 pFile = fopen( pFileName,
"rb" );
613 printf(
"Amap_LibertyFileSize(): The input file is unavailable (absent or open).\n" );
617 nFileSize = ftell( pFile );
636 for ( pHead = pFileName; *pHead; pHead++ )
655 for ( ; pBeg < pEnd; pBeg++ )
656 Counter += (*pBeg ==
'(' || *pBeg ==
':');
673 char * pCur, * pStart;
674 for ( pCur = pBeg; pCur < pEnd; pCur++ )
675 if ( pCur[0] ==
'/' && pCur[1] ==
'*' )
676 for ( pStart = pCur; pCur < pEnd; pCur++ )
677 if ( pCur[0] ==
'*' && pCur[1] ==
'/' )
679 for ( ; pStart < pCur + 2; pStart++ )
680 if ( *pStart !=
'\n' ) *pStart =
' ';
696static inline int Amap_LibertyCharIsSpace(
char c )
698 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' || c ==
'\\';
712static inline int Amap_LibertySkipSpaces(
Amap_Tree_t *
p,
char ** ppPos,
char * pEnd,
int fStopAtNewLine )
714 char * pPos = *ppPos;
715 for ( ; pPos < pEnd; pPos++ )
720 if ( fStopAtNewLine )
723 if ( !Amap_LibertyCharIsSpace(*pPos) )
741static inline int Amap_LibertySkipEntry(
char ** ppPos,
char * pEnd )
743 char * pPos = *ppPos;
746 for ( pPos++; pPos < pEnd; pPos++ )
755 for ( ; pPos < pEnd; pPos++ )
756 if ( *pPos ==
' ' || *pPos ==
'\r' || *pPos ==
'\n' || *pPos ==
'\t' ||
757 *pPos ==
':' || *pPos ==
';' ||
758 *pPos ==
'(' || *pPos ==
')' ||
759 *pPos ==
'{' || *pPos ==
'}' )
777static inline char * Amap_LibertyFindMatch(
char * pPos,
char * pEnd )
780 assert( *pPos ==
'(' || *pPos ==
'{' );
783 for ( ; pPos < pEnd; pPos++ )
795 for ( ; pPos < pEnd; pPos++ )
805 assert( *pPos ==
')' || *pPos ==
'}' );
823 char * pBeg =
p->pContents + Head.
Beg;
824 char * pEnd =
p->pContents + Head.
End;
825 char * pFirstNonSpace = NULL;
826 char * pLastNonSpace = NULL;
828 for ( pChar = pBeg; pChar < pEnd; pChar++ )
830 if ( *pChar ==
'\n' )
832 if ( Amap_LibertyCharIsSpace(*pChar) )
834 pLastNonSpace = pChar;
835 if ( pFirstNonSpace == NULL )
836 pFirstNonSpace = pChar;
838 if ( pFirstNonSpace == NULL || pLastNonSpace == NULL )
840 assert( pFirstNonSpace && pLastNonSpace );
841 Res.
Beg = pFirstNonSpace -
p->pContents;
842 Res.
End = pLastNonSpace -
p->pContents + 1;
859 p->pItems[
p->nItems].iLine =
p->nLines;
860 p->pItems[
p->nItems].Type = Type;
861 p->pItems[
p->nItems].Child = -1;
862 p->pItems[
p->nItems].Next = -1;
863 return p->pItems +
p->nItems++;
881 char * pNext, * pStop;
883 if ( Amap_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
885 Key.
Beg = *ppPos -
p->pContents;
886 if ( Amap_LibertySkipEntry( ppPos, pEnd ) )
888 Key.
End = *ppPos -
p->pContents;
889 if ( Amap_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
895 if ( Amap_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
897 Head.
Beg = *ppPos -
p->pContents;
898 if ( Amap_LibertySkipEntry( ppPos, pEnd ) )
900 Head.
End = *ppPos -
p->pContents;
901 if ( Amap_LibertySkipSpaces(
p, ppPos, pEnd, 1 ) )
904 if ( *pNext !=
';' && *pNext !=
'\n' )
910 pItem->
Head = Amap_LibertyUpdateHead(
p, Head );
912 if ( pItem->
Next == -1 )
914 return Amap_LibertyItemId(
p, pItem );
918 pStop = Amap_LibertyFindMatch( pNext, pEnd );
919 Head.
Beg = pNext -
p->pContents + 1;
920 Head.
End = pStop -
p->pContents;
922 if ( Amap_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
927 pItem->
Head = Amap_LibertyUpdateHead(
p, Head );
928 return Amap_LibertyItemId(
p, pItem );
933 pStop = Amap_LibertyFindMatch( pNext, pEnd );
934 Body.
Beg = pNext -
p->pContents + 1;
935 Body.
End = pStop -
p->pContents;
939 pItem->
Head = Amap_LibertyUpdateHead(
p, Head );
943 if ( pItem->
Child == -1 )
947 if ( pItem->
Next == -1 )
949 return Amap_LibertyItemId(
p, pItem );
956 pItem->
Head = Amap_LibertyUpdateHead(
p, Head );
958 if ( pItem->
Next == -1 )
960 return Amap_LibertyItemId(
p, pItem );
963 if (
p->pError == NULL )
966 sprintf(
p->pError,
"File \"%s\". Line %6d. Failed to parse entry \"%s\".\n",
994 if (
p->nContents == 0 )
999 pFile = fopen( pFileName,
"rb" );
1001 RetValue = fread(
p->pContents,
p->nContents, 1, pFile );
1003 p->pContents[
p->nContents] = 0;
1005 p->pFileName = Abc_UtilStrsav( pFileName );
1053 pPos =
p->pContents;
1058 printf(
"Parsing finished successfully.\n" );
1066 printf(
"%s",
p->pError );
1068 printf(
"Parsing failed.\n" );
1073 printf(
"Memory = %7.2f MB. ", 1.0*(
p->nContents+
p->nItermAlloc*
sizeof(
Amap_Item_t))/(1<<20) );
1074 ABC_PRT(
"Time", Abc_Clock() - clk );
1101 pPos =
p->pContents;
1106 printf(
"Parsing finished successfully.\n" );
1114 printf(
"%s",
p->pError );
1116 printf(
"Parsing failed.\n" );
1121 printf(
"Memory = %7.2f MB. ", 1.0*(
p->nContents+
p->nItermAlloc*
sizeof(
Amap_Item_t))/(1<<20) );
1122 ABC_PRT(
"Time", Abc_Clock() - clk );
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
char * Amap_LibertyGetStringFormula(Amap_Tree_t *p, Amap_Pair_t Pair)
void Amap_LibertyWipeOutComments(char *pBeg, char *pEnd)
int Amap_LibertyCellCountOutputs(Amap_Tree_t *p, Amap_Item_t *pCell)
int Amap_LibertyPrintLiberty(Amap_Tree_t *p, char *pFileName)
void Amap_LibertyStop(Amap_Tree_t *p)
Amap_Item_t * Amap_LibertyCellArea(Amap_Tree_t *p, Amap_Item_t *pCell)
struct Amap_Pair_t_ Amap_Pair_t
struct Amap_Tree_t_ Amap_Tree_t
struct Amap_Item_t_ Amap_Item_t
char * Amap_LibertyTimeStamp()
Amap_Item_t * Amap_LibertyPinFunction(Amap_Tree_t *p, Amap_Item_t *pPin)
int Amap_LibertyCellIsFlop(Amap_Tree_t *p, Amap_Item_t *pCell)
int Amap_LibertyFileSize(char *pFileName)
void Amap_LibertyPrintLibertyItem(FILE *pFile, Amap_Tree_t *p, Amap_Item_t *pItem, int nOffset)
FUNCTION DEFINITIONS ///.
void Amap_LibertyFixFileHead(char *pFileName)
int Amap_LibertyBuildItem(Amap_Tree_t *p, char **ppPos, char *pEnd)
#define ABC_MAX_LIB_STR_LEN
DECLARATIONS ///.
Amap_Item_t * Amap_LibertyCellOutput(Amap_Tree_t *p, Amap_Item_t *pCell)
char * Amap_LibertyGetString(Amap_Tree_t *p, Amap_Pair_t Pair)
Vec_Str_t * Amap_LibertyParseStr(char *pFileName, int fVerbose)
Vec_Str_t * Amap_LibertyPrintGenlibStr(Amap_Tree_t *p, int fVerbose)
int Amap_LibertyCellIsDontUse(Amap_Tree_t *p, Amap_Item_t *pCell)
int Amap_LibertyCountItems(char *pBeg, char *pEnd)
Amap_Tree_t * Amap_LibertyStart(char *pFileName)
int Amap_LibertyParse(char *pFileName, int fVerbose)
#define Amap_ItemForEachChild(p, pItem, pChild)
int Amap_LibertyPrintGenlib(Amap_Tree_t *p, char *pFileName, int fVerbose)
Vec_Ptr_t * Amap_LibertyCellOutputs(Amap_Tree_t *p, Amap_Item_t *pCell)
struct Vec_Str_t_ Vec_Str_t
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.