23#pragma comment(lib, "shlwapi.lib")
85static inline int Scl_LibertyGlobMatch(
const char * pattern,
const char *
string) {
87 return PathMatchSpec(
string, pattern);
89 return fnmatch(pattern,
string, 0) == 0;
95static inline void Scl_PrintWord( FILE * pFile,
Scl_Tree_t *
p,
Scl_Pair_t Pair ) {
char * pBeg =
p->pContents+Pair.
Beg, * pEnd =
p->pContents+Pair.
End;
while ( pBeg < pEnd ) fputc( *pBeg++, pFile ); }
96static inline void Scl_PrintSpace( FILE * pFile,
long nOffset ) {
long i;
for ( i = 0; i < nOffset; i++ ) fputc(
' ', pFile); }
99#define Scl_ItemForEachChild( p, pItem, pChild ) \
100 for ( pChild = Scl_LibertyItem(p, pItem->Child); pChild; pChild = Scl_LibertyItem(p, pChild->Next) )
101#define Scl_ItemForEachChildName( p, pItem, pChild, pName ) \
102 for ( pChild = Scl_LibertyItem(p, pItem->Child); pChild; pChild = Scl_LibertyItem(p, pChild->Next) ) if ( Scl_LibertyCompare(p, pChild->Key, pName) ) {} else
123 Scl_PrintSpace( pFile, nOffset );
124 Scl_PrintWord( pFile,
p, pItem->
Key );
125 fprintf( pFile,
"(" );
126 Scl_PrintWord( pFile,
p, pItem->
Head );
127 fprintf( pFile,
") {\n" );
128 if ( Scl_LibertyItem(
p, pItem->
Child) )
130 Scl_PrintSpace( pFile, nOffset );
131 fprintf( pFile,
"}\n" );
135 Scl_PrintSpace( pFile, nOffset );
136 Scl_PrintWord( pFile,
p, pItem->
Key );
137 fprintf( pFile,
" : " );
138 Scl_PrintWord( pFile,
p, pItem->
Head );
139 fprintf( pFile,
";\n" );
143 Scl_PrintSpace( pFile, nOffset );
144 Scl_PrintWord( pFile,
p, pItem->
Key );
145 fprintf( pFile,
"(" );
146 Scl_PrintWord( pFile,
p, pItem->
Head );
147 fprintf( pFile,
");\n" );
150 if ( Scl_LibertyItem(
p, pItem->
Next) )
156 if ( pFileName == NULL )
160 pFile = fopen( pFileName,
"w" );
163 printf(
"Scl_LibertyParseDump(): The output file is unavailable (absent or open).\n" );
168 if ( pFile != stdout )
188 for ( ; pBeg < pEnd; pBeg++ )
189 Counter += (*pBeg ==
'(' || *pBeg ==
':');
210 char * pCur, * pStart;
211 for ( pCur = pBeg; pCur < pEnd-1; pCur++ )
212 if ( pCur[0] ==
'/' && pCur[1] ==
'*' )
214 for ( pStart = pCur; pCur < pEnd-1; pCur++ )
215 if ( pCur[0] ==
'*' && pCur[1] ==
'/' )
217 for ( ; pStart < pCur + 2; pStart++ )
218 if ( *pStart !=
'\n' ) *pStart =
' ';
222 else if ( pCur[0] ==
'/' && pCur[1] ==
'/' )
224 for ( pStart = pCur; pCur < pEnd; pCur++ )
225 if ( pCur[0] ==
'\n' || pCur == pEnd-1 )
227 for ( ; pStart < pCur; pStart++ ) *pStart =
' ';
232static inline long Scl_LibertyCharIsSpace(
char c )
234 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' || c ==
'\\';
236static inline long Scl_LibertySkipSpaces(
Scl_Tree_t *
p,
char ** ppPos,
char * pEnd,
int fStopAtNewLine )
238 char * pPos = *ppPos;
239 for ( ; pPos < pEnd; pPos++ )
244 if ( fStopAtNewLine )
247 if ( !Scl_LibertyCharIsSpace(*pPos) )
254static inline long Scl_LibertySkipEntry(
char ** ppPos,
char * pEnd )
256 char * pPos = *ppPos;
259 for ( pPos++; pPos < pEnd; pPos++ )
268 for ( ; pPos < pEnd; pPos++ )
269 if ( *pPos ==
' ' || *pPos ==
'\r' || *pPos ==
'\n' || *pPos ==
'\t' ||
270 *pPos ==
':' || *pPos ==
';' ||
271 *pPos ==
'(' || *pPos ==
')' ||
272 *pPos ==
'{' || *pPos ==
'}' )
279static inline char * Scl_LibertyFindMatch(
char * pPos,
char * pEnd )
282 assert( *pPos ==
'(' || *pPos ==
'{' );
287 for ( ; pPos < pEnd; pPos++ )
290 if ( *pPos ==
'(' ) {
294 else if ( *pPos ==
')' ) {
305 for ( ; pPos < pEnd; pPos++ )
308 if ( *pPos ==
'{' ) {
312 else if ( *pPos ==
'}' ) {
319 assert( *pPos ==
')' || *pPos ==
'}' );
326 char * pBeg =
p->pContents + Head.
Beg;
327 char * pEnd =
p->pContents + Head.
End;
328 char * pFirstNonSpace = NULL;
329 char * pLastNonSpace = NULL;
331 for ( pChar = pBeg; pChar < pEnd; pChar++ )
333 if ( *pChar ==
'\n' ) {
338 }
else if ( Scl_LibertyCharIsSpace(*pChar) ) {
341 pLastNonSpace = pChar;
342 if ( pFirstNonSpace == NULL )
343 pFirstNonSpace = pChar;
345 if ( pFirstNonSpace == NULL || pLastNonSpace == NULL )
347 assert( pFirstNonSpace && pLastNonSpace );
348 Res.
Beg = pFirstNonSpace -
p->pContents;
349 Res.
End = pLastNonSpace -
p->pContents + 1;
355 p->pItems[
p->nItems].iLine =
p->nLines;
356 p->pItems[
p->nItems].Type = Type;
357 p->pItems[
p->nItems].Child = -1;
358 p->pItems[
p->nItems].Next = -1;
359 return p->pItems +
p->nItems++;
378 if ( Pair.
End - Pair.
Beg + 2 > Vec_StrSize(
p->vBuffer) )
379 Vec_StrFill(
p->vBuffer, Pair.
End - Pair.
Beg + 100,
'\0' );
380 Buffer = Vec_StrArray(
p->vBuffer );
382 if ( Pair.
Beg < Pair.
End && Buffer[0] ==
'\"' )
385 Buffer[Pair.
End-Pair.
Beg-1] = 0;
388 Buffer[Pair.
End-Pair.
Beg] = 0;
415 char * pNext, * pStop;
417 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
419 Key.
Beg = *ppPos -
p->pContents;
420 if ( Scl_LibertySkipEntry( ppPos, pEnd ) )
422 Key.
End = *ppPos -
p->pContents;
423 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
429 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
431 Head.
Beg = *ppPos -
p->pContents;
432 if ( Scl_LibertySkipEntry( ppPos, pEnd ) )
434 Head.
End = *ppPos -
p->pContents;
435 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 1 ) )
438 while ( *pNext ==
'+' || *pNext ==
'-' || *pNext ==
'*' || *pNext ==
'/' )
441 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
443 if ( Scl_LibertySkipEntry( ppPos, pEnd ) )
445 Head.
End = *ppPos -
p->pContents;
446 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 1 ) )
450 if ( *pNext !=
';' && *pNext !=
'\n' )
456 pItem->
Head = Scl_LibertyUpdateHead(
p, Head );
458 if ( pItem->
Next == -1 )
460 return Scl_LibertyItemId(
p, pItem );
464 pStop = Scl_LibertyFindMatch( pNext, pEnd );
465 Head.
Beg = pNext -
p->pContents + 1;
466 Head.
End = pStop -
p->pContents;
468 if ( Scl_LibertySkipSpaces(
p, ppPos, pEnd, 0 ) )
473 pItem->
Head = Scl_LibertyUpdateHead(
p, Head );
474 return Scl_LibertyItemId(
p, pItem );
479 pStop = Scl_LibertyFindMatch( pNext, pEnd );
480 Body.
Beg = pNext -
p->pContents + 1;
481 Body.
End = pStop -
p->pContents;
485 pItem->
Head = Scl_LibertyUpdateHead(
p, Head );
489 if ( pItem->
Child == -1 )
493 if ( pItem->
Next == -1 )
495 return Scl_LibertyItemId(
p, pItem );
502 pItem->
Head = Scl_LibertyUpdateHead(
p, Head );
504 if ( pItem->
Next == -1 )
506 return Scl_LibertyItemId(
p, pItem );
514 if (
p->pError == NULL )
517 sprintf(
p->pError,
"File \"%s\". Line %6ld. Failed to parse entry \"%s\".\n",
537 for ( pHead = pFileName; *pHead; pHead++ )
545 pFile = fopen( pFileName,
"rb" );
548 printf(
"Scl_LibertyFileSize(): The input file is unavailable (absent or open).\n" );
552 nFileSize = ftell( pFile );
557static char * Io_LibLoadFileGz(
char * pFileName,
long * pnFileSize )
559 const int READ_BLOCK_SIZE = 100000;
562 long amtRead, readBlock, nFileSize = READ_BLOCK_SIZE;
563 pFile =
gzopen( pFileName,
"rb" );
564 pContents =
ABC_ALLOC(
char, nFileSize );
566 while ((amtRead =
gzread(pFile, pContents + readBlock * READ_BLOCK_SIZE, READ_BLOCK_SIZE)) == READ_BLOCK_SIZE) {
568 nFileSize += READ_BLOCK_SIZE;
569 pContents =
ABC_REALLOC(
char, pContents, nFileSize);
574 nFileSize -= (READ_BLOCK_SIZE - amtRead);
576 *pnFileSize = nFileSize;
582 char * pContents = NULL;
586 FILE * pFile = fopen( pFileName,
"rb" );
589 pContents = Io_LibLoadFileGz( pFileName, nContents );
590 if(pContents == NULL) {
591 printf(
"Scl_LibertyFileContents(): The input file is unavailable (absent or open).\n" );
602 FILE * pFile = fopen( pFileName,
"rb" );
603 pContents =
ABC_ALLOC(
char, *nContents+1 );
605 RetValue = fread( pContents, *nContents, 1, pFile );
607 pContents[*nContents] = 0;
613 FILE * pFile = fopen( pFileName,
"wb" );
617 printf(
"Scl_LibertyStringDump(): The output file is unavailable.\n" );
620 RetValue = fwrite( Vec_StrArray(vStr), 1, Vec_StrSize(vStr), pFile );
647 p->clkStart = Abc_Clock();
648 p->nContents = RetValue;
651 p->pFileName = Abc_UtilStrsav( pFileName );
656 p->vBuffer = Vec_StrStart( 10 );
663 printf(
"Memory = %7.2f MB. ", 1.0 * (
p->nContents +
p->nItermAlloc *
sizeof(
Scl_Item_t))/(1<<20) );
664 ABC_PRT(
"Time", Abc_Clock() -
p->clkStart );
666 Vec_StrFree(
p->vBuffer );
683 if (
p->pError ) printf(
"%s",
p->pError );
684 printf(
"Parsing failed. " );
685 Abc_PrintTime( 1,
"Parsing time", Abc_Clock() -
p->clkStart );
689 printf(
"Parsing finished successfully. " );
690 Abc_PrintTime( 1,
"Parsing time", Abc_Clock() -
p->clkStart );
710 if ( !Scl_LibertyCompare(
p, pAttr->
Key,
"ff") ||
711 !Scl_LibertyCompare(
p, pAttr->
Key,
"latch") )
720 if ( !Scl_LibertyCompare(
p, pAttr->
Key,
"dont_use") )
723 for (
int i = 0; i < dont_use.
size; i++) {
724 if (Scl_LibertyGlobMatch(dont_use.
dont_use_list[i], cell_name)) {
748 if ( pChild && !Scl_LibertyCompare(
p, pChild->
Key,
"when") )
796 vStr = Vec_StrAlloc( 1000 );
797 Vec_StrPrintStr( vStr,
"GATE _const0_ 0.000000 z=CONST0;\n" );
798 Vec_StrPrintStr( vStr,
"GATE _const1_ 0.000000 z=CONST1;\n" );
808 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" due to dont_use attribute.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
813 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped three-state cell \"%s\".\n",
Scl_LibertyReadString(
p, pCell->
Head) );
818 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" without logic function.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
828 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" with constant formula \"%s\".\n",
Scl_LibertyReadString(
p, pCell->
Head), pFormula );
831 Vec_StrPrintStr( vStr,
"GATE " );
833 Vec_StrPrintStr( vStr,
" " );
835 Vec_StrPrintStr( vStr,
" " );
837 Vec_StrPrintStr( vStr,
"=" );
838 Vec_StrPrintStr( vStr, pFormula );
839 Vec_StrPrintStr( vStr,
";\n" );
845 Vec_StrPrintStr( vStr,
" PIN " );
847 Vec_StrPrintStr( vStr,
" UNKNOWN 1 999 1.00 0.00 1.00 0.00\n" );
851 Vec_StrPrintStr( vStr,
"\n.end\n" );
852 Vec_StrPush( vStr,
'\0' );
870static inline void Vec_StrPutI_(
Vec_Str_t * vOut,
int Val ) { printf(
"%d ", Val ); Vec_StrPutI( vOut, Val ); }
871static inline void Vec_StrPutW_(
Vec_Str_t * vOut,
word Val ) { printf(
"%lu ", (
long)Val ); Vec_StrPutW( vOut, Val ); }
872static inline void Vec_StrPutF_(
Vec_Str_t * vOut,
float Val ) { printf(
"%f ", Val ); Vec_StrPutF( vOut, Val ); }
873static inline void Vec_StrPutS_(
Vec_Str_t * vOut,
char * Val ) { printf(
"%s ", Val ); Vec_StrPutS( vOut, Val ); }
874static inline void Vec_StrPut_(
Vec_Str_t * vOut ) { printf(
"\n" ); }
876static inline void Vec_StrPutI_(
Vec_Str_t * vOut,
int Val ) { Vec_StrPutI( vOut, Val ); }
877static inline void Vec_StrPutW_(
Vec_Str_t * vOut,
word Val ) { Vec_StrPutW( vOut, Val ); }
878static inline void Vec_StrPutF_(
Vec_Str_t * vOut,
float Val ) { Vec_StrPutF( vOut, Val ); }
879static inline void Vec_StrPutS_(
Vec_Str_t * vOut,
char * Val ) { Vec_StrPutS( vOut, Val ); }
880static inline void Vec_StrPut_(
Vec_Str_t * vOut ) { }
922 if ( !
strcmp(pUnit,
"1ns") )
924 if ( !
strcmp(pUnit,
"100ps") )
926 if ( !
strcmp(pUnit,
"10ps") )
928 if ( !
strcmp(pUnit,
"1ps") )
932 printf(
"Liberty parser cannot read \"time_unit\". Assuming time_unit : \"1ns\".\n" );
942 float First =
atof(
strtok(pHead,
" \t\n\r\\\","));
943 char * pSecond =
strtok(NULL,
" \t\n\r\\\",");
944 Vec_StrPutF_( vOut, First );
945 if ( pSecond && !
strcmp(pSecond,
"pf") )
946 Vec_StrPutI_( vOut, 12 );
947 else if ( pSecond && !
strcmp(pSecond,
"ff") )
948 Vec_StrPutI_( vOut, 15 );
952 printf(
"Liberty parser cannot read \"capacitive_load_unit\". Assuming capacitive_load_unit(1, pf).\n" );
953 Vec_StrPutF_( vOut, 1.0 );
954 Vec_StrPutI_( vOut, 12 );
974 int First = atoi(
strtok(pHead,
" ,") );
976 Vec_StrPutI_( vOut, First );
977 Vec_StrPutF_( vOut, Second );
1000 char * pThird =
strtok(NULL,
" ");
1001 if ( pThird[0] ==
'\"' )
1003 Vec_StrPutF_( vOut, First );
1004 Vec_StrPutF_( vOut, Second );
1005 Vec_StrPutS_( vOut, pThird );
1006 Vec_StrPut_( vOut );
1008 Vec_StrPut_( vOut );
1010 Vec_StrPut_( vOut );
1025 if ( !
strcmp(pToken,
"input") )
1027 if ( !
strcmp(pToken,
"output") )
1029 if ( !
strcmp(pToken,
"internal") )
1055 vTimings = Vec_PtrAlloc( 16 );
1059 Vec_PtrPush( vTimings, pTiming );
1068 if ( !
strcmp(pToken,
"positive_unate") )
1070 if ( !
strcmp(pToken,
"negative_unate") )
1072 if ( !
strcmp(pToken,
"non_unate") )
1081 Vec_Flt_t * vValues = Vec_FltAlloc( 100 );
1082 for ( pToken =
strtok(pName,
" \t\n\r\\\","); pToken; pToken =
strtok(NULL,
" \t\n\r\\\",") )
1083 Vec_FltPush( vValues,
atof(pToken) );
1091 Vec_StrPutI_( vOut, Vec_FltSize(vInd1) );
1093 Vec_StrPutF_( vOut, Entry );
1094 Vec_StrPut_( vOut );
1096 Vec_StrPutI_( vOut, Vec_FltSize(vInd2) );
1098 Vec_StrPutF_( vOut, Entry );
1099 Vec_StrPut_( vOut );
1100 Vec_StrPut_( vOut );
1102 assert( Vec_FltSize(vInd1) * Vec_FltSize(vInd2) == Vec_FltSize(vValues) );
1105 Vec_StrPutF_( vOut, Entry );
1106 if ( i % Vec_FltSize(vInd2) == Vec_FltSize(vInd2)-1 )
1107 Vec_StrPut_( vOut );
1110 Vec_StrPut_( vOut );
1111 for ( i = 0; i < 3; i++ )
1112 Vec_StrPutF_( vOut, 0 );
1113 for ( i = 0; i < 4; i++ )
1114 Vec_StrPutF_( vOut, 0 );
1115 for ( i = 0; i < 6; i++ )
1116 Vec_StrPutF_( vOut, 0 );
1117 Vec_StrPut_( vOut );
1118 Vec_StrPut_( vOut );
1127 char * pThis, * pTempl = NULL;
1133 if ( pTable == NULL )
1137 if ( pTempl == NULL || pTempl[0] == 0 )
1142 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_1") )
1144 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_2") )
1146 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"values") )
1149 if ( vIndex1 == NULL || vIndex2 == NULL || vValues == NULL )
1150 { printf(
"Incomplete table specification\n" );
return 0; }
1155 Vec_PtrPush( vOut, vInd1 );
1156 Vec_PtrPush( vOut, vInd2 );
1157 Vec_PtrPush( vOut, vValues );
1159 else if ( !
strcmp(pTempl,
"scalar") )
1162 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"values") )
1166 assert( Vec_FltSize(vValues) == 1 );
1168 Vec_PtrPush( vOut, Vec_IntStart(1) );
1169 Vec_PtrPush( vOut, Vec_IntStart(1) );
1170 Vec_PtrPush( vOut, vValues );
1174 { printf(
"Cannot read \"scalar\" template\n" );
return 0; }
1181 if ( i % 4 == 0 && !
strcmp(pTempl, pThis) )
1187 { printf(
"Template cannot be found in the template library\n" );
return 0; }
1191 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_1") )
1193 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_2") )
1195 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"values") )
1199 vInd1 = (
Vec_Flt_t *)Vec_PtrEntry( vTemples, iPlace + 2 );
1200 vInd2 = (
Vec_Flt_t *)Vec_PtrEntry( vTemples, iPlace + 3 );
1201 if ( Vec_PtrEntry(vTemples, iPlace + 1) == NULL )
1203 assert( !vIndex1 || Vec_FltSize(vIndex1) == Vec_FltSize(vInd1) );
1204 assert( !vIndex2 || Vec_FltSize(vIndex2) == Vec_FltSize(vInd2) );
1205 vInd1 = vIndex1 ? vIndex1 : vInd1;
1206 vInd2 = vIndex2 ? vIndex2 : vInd2;
1208 Vec_PtrPush( vOut, Vec_FltDup(vInd1) );
1209 Vec_PtrPush( vOut, Vec_FltDup(vInd2) );
1210 Vec_PtrPush( vOut, Vec_FltDup(vValues) );
1214 Vec_Flt_t * vValues2 = Vec_FltAlloc( Vec_FltSize(vValues) );
1215 assert( !vIndex2 || Vec_FltSize(vIndex2) == Vec_FltSize(vInd1) );
1216 assert( !vIndex1 || Vec_FltSize(vIndex1) == Vec_FltSize(vInd2) );
1217 vInd1 = vIndex2 ? vIndex2 : vInd1;
1218 vInd2 = vIndex1 ? vIndex1 : vInd2;
1220 assert( Vec_FltSize(vInd1) * Vec_FltSize(vInd2) == Vec_FltSize(vValues) );
1223 int x = i % Vec_FltSize(vInd2);
1224 int y = i / Vec_FltSize(vInd2);
1225 Entry = Vec_FltEntry( vValues, x * Vec_FltSize(vInd1) + y );
1226 Vec_FltPush( vValues2, Entry );
1228 assert( Vec_FltSize(vValues) == Vec_FltSize(vValues2) );
1230 Vec_PtrPush( vOut, Vec_FltDup(vInd1) );
1231 Vec_PtrPush( vOut, Vec_FltDup(vInd2) );
1232 Vec_PtrPush( vOut, vValues2 );
1234 Vec_FltFreeP( &vIndex1 );
1235 Vec_FltFreeP( &vIndex2 );
1236 Vec_FltFreeP( &vValues );
1244 int i, k, nTriples = Vec_PtrSize(vTables) / 3;
1246 assert( Vec_PtrSize(vTables) > 0 && Vec_PtrSize(vTables) % 3 == 0 );
1247 if ( nTriples == 1 )
1249 *pvInd0 = (
Vec_Flt_t *)Vec_PtrEntry(vTables, 0);
1250 *pvInd1 = (
Vec_Flt_t *)Vec_PtrEntry(vTables, 1);
1251 *pvValues = (
Vec_Flt_t *)Vec_PtrEntry(vTables, 2);
1252 Vec_PtrShrink( vTables, 0 );
1255 vInd0 = Vec_FltDup( (
Vec_Flt_t *)Vec_PtrEntry(vTables, 0) );
1256 vInd1 = Vec_FltDup( (
Vec_Flt_t *)Vec_PtrEntry(vTables, 1) );
1257 vValues = Vec_FltDup( (
Vec_Flt_t *)Vec_PtrEntry(vTables, 2) );
1258 for ( i = 1; i < nTriples; i++ )
1260 vind0 = (
Vec_Flt_t *)Vec_PtrEntry(vTables, i*3+0);
1261 vind1 = (
Vec_Flt_t *)Vec_PtrEntry(vTables, i*3+1);
1262 vvalues = (
Vec_Flt_t *)Vec_PtrEntry(vTables, i*3+2);
1264 if ( !Vec_FltEqual(vind0, vInd0) )
1266 if ( !Vec_FltEqual(vind1, vInd1) )
1271 if ( Vec_FltEntry(vValues, k) < Entry )
1272 Vec_FltWriteEntry( vValues, k, Entry );
1279 *pvValues = vValues;
1290 char * pThis, * pTempl = NULL;
1296 if ( pTable == NULL )
1300 if ( pTempl == NULL || pTempl[0] == 0 )
1305 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_1") )
1307 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_2") )
1309 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"values") )
1312 if ( vIndex1 == NULL || vIndex2 == NULL || vValues == NULL )
1313 { printf(
"Incomplete table specification\n" );
return 0; }
1318 Vec_StrPutI_( vOut, Vec_FltSize(vInd1) );
1320 Vec_StrPutF_( vOut, Entry );
1321 Vec_StrPut_( vOut );
1323 Vec_StrPutI_( vOut, Vec_FltSize(vInd2) );
1325 Vec_StrPutF_( vOut, Entry );
1326 Vec_StrPut_( vOut );
1327 Vec_StrPut_( vOut );
1329 assert( Vec_FltSize(vInd1) * Vec_FltSize(vInd2) == Vec_FltSize(vValues) );
1332 Vec_StrPutF_( vOut, Entry );
1333 if ( i % Vec_FltSize(vInd2) == Vec_FltSize(vInd2)-1 )
1334 Vec_StrPut_( vOut );
1342 if ( i % 4 == 0 && !
strcmp(pTempl, pThis) )
1348 { printf(
"Template cannot be found in the template library\n" );
return 0; }
1352 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_1") )
1354 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_2") )
1356 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"values") )
1360 vInd1 = (
Vec_Flt_t *)Vec_PtrEntry( vTemples, iPlace + 2 );
1361 vInd2 = (
Vec_Flt_t *)Vec_PtrEntry( vTemples, iPlace + 3 );
1362 if ( Vec_PtrEntry(vTemples, iPlace + 1) == NULL )
1364 assert( !vIndex1 || Vec_FltSize(vIndex1) == Vec_FltSize(vInd1) );
1365 assert( !vIndex2 || Vec_FltSize(vIndex2) == Vec_FltSize(vInd2) );
1366 vInd1 = vIndex1 ? vIndex1 : vInd1;
1367 vInd2 = vIndex2 ? vIndex2 : vInd2;
1369 Vec_StrPutI_( vOut, Vec_FltSize(vInd1) );
1371 Vec_StrPutF_( vOut, Entry );
1372 Vec_StrPut_( vOut );
1374 Vec_StrPutI_( vOut, Vec_FltSize(vInd2) );
1376 Vec_StrPutF_( vOut, Entry );
1377 Vec_StrPut_( vOut );
1378 Vec_StrPut_( vOut );
1380 assert( Vec_FltSize(vInd1) * Vec_FltSize(vInd2) == Vec_FltSize(vValues) );
1383 Vec_StrPutF_( vOut, Entry );
1384 if ( i % Vec_FltSize(vInd2) == Vec_FltSize(vInd2)-1 )
1385 Vec_StrPut_( vOut );
1390 assert( !vIndex2 || Vec_FltSize(vIndex2) == Vec_FltSize(vInd1) );
1391 assert( !vIndex1 || Vec_FltSize(vIndex1) == Vec_FltSize(vInd2) );
1392 vInd1 = vIndex2 ? vIndex2 : vInd1;
1393 vInd2 = vIndex1 ? vIndex1 : vInd2;
1395 Vec_StrPutI_( vOut, Vec_FltSize(vInd1) );
1397 Vec_StrPutF_( vOut, Entry );
1398 Vec_StrPut_( vOut );
1400 Vec_StrPutI_( vOut, Vec_FltSize(vInd2) );
1402 Vec_StrPutF_( vOut, Entry );
1403 Vec_StrPut_( vOut );
1404 Vec_StrPut_( vOut );
1406 assert( Vec_FltSize(vInd1) * Vec_FltSize(vInd2) == Vec_FltSize(vValues) );
1409 int x = i % Vec_FltSize(vInd2);
1410 int y = i / Vec_FltSize(vInd2);
1411 Entry = Vec_FltEntry( vValues, x * Vec_FltSize(vInd1) + y );
1412 Vec_StrPutF_( vOut, Entry );
1413 if ( i % Vec_FltSize(vInd2) == Vec_FltSize(vInd2)-1 )
1414 Vec_StrPut_( vOut );
1418 Vec_StrPut_( vOut );
1419 for ( i = 0; i < 3; i++ )
1420 Vec_StrPutF_( vOut, 0 );
1421 for ( i = 0; i < 4; i++ )
1422 Vec_StrPutF_( vOut, 0 );
1423 for ( i = 0; i < 6; i++ )
1424 Vec_StrPutF_( vOut, 0 );
1425 Vec_FltFreeP( &vIndex1 );
1426 Vec_FltFreeP( &vIndex2 );
1427 Vec_FltFreeP( &vValues );
1428 Vec_StrPut_( vOut );
1429 Vec_StrPut_( vOut );
1435 assert( Vec_PtrSize(vRes) % 4 == 0 );
1436 printf(
"There are %d slew/load templates\n", Vec_PtrSize(vRes) % 4 );
1440 printf(
"%s\n", (
char *)vArray );
1441 else if ( i % 4 == 1 )
1442 printf(
"%d\n", (
int)(vArray != NULL) );
1443 else if ( i % 4 == 2 || i % 4 == 3 )
1444 Vec_FltPrint( vArray );
1454 char * pVar1, * pVar2;
1456 vRes = Vec_PtrAlloc( 100 );
1459 pVar1 = pVar2 = NULL;
1460 vIndex1 = vIndex2 = NULL;
1463 if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_1") )
1465 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"index_2") )
1467 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"variable_1") )
1469 else if ( !Scl_LibertyCompare(
p, pItem->
Key,
"variable_2") )
1472 if ( pVar1 == NULL || pVar2 == NULL )
1476 Vec_FltFreeP( &vIndex1 );
1477 Vec_FltFreeP( &vIndex2 );
1480 assert( pVar1 != NULL && pVar2 != NULL );
1481 fFlag0 = (!
strcmp(pVar1,
"input_net_transition") && !
strcmp(pVar2,
"total_output_net_capacitance"));
1482 fFlag1 = (!
strcmp(pVar2,
"input_net_transition") && !
strcmp(pVar1,
"total_output_net_capacitance"));
1485 if ( !fFlag0 && !fFlag1 )
1487 Vec_FltFreeP( &vIndex1 );
1488 Vec_FltFreeP( &vIndex2 );
1492 Vec_PtrPush( vRes, fFlag0 ? NULL : (
void *)(ABC_PTRINT_T)1 );
1493 Vec_PtrPush( vRes, fFlag0 ? vIndex1 : vIndex2 );
1494 Vec_PtrPush( vRes, fFlag0 ? vIndex2 : vIndex1 );
1496 if ( Vec_PtrSize(vRes) == 0 )
1497 Abc_Print( 0,
"Templates are not defined.\n" );
1505 int fUseFirstTable = 0;
1507 Vec_Ptr_t * vNameIns, * vTemples = NULL;
1510 char * pFormula, * pName;
1511 int i, k, Counter, nOutputs, nCells;
1512 int nSkipped[6] = {0};
1518 vOut = Vec_StrAlloc( 10000 );
1522 Vec_StrPut_( vOut );
1529 Vec_StrPut_( vOut );
1530 Vec_StrPut_( vOut );
1542 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped sequential cell \"%s\".\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1548 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" due to dont_use attribute.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1554 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped three-state cell \"%s\".\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1560 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" without logic function.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1566 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" with more than two outputs.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1570 if ( fSkipMultiOuts && Counter > 1 )
1572 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" with two outputs.\n",
Scl_LibertyReadString(
p, pCell->
Head) );
1579 Vec_StrPutI_( vOut, nCells );
1580 Vec_StrPut_( vOut );
1581 Vec_StrPut_( vOut );
1594 if ( fSkipMultiOuts && Counter > 1 )
1599 Vec_StrPutF_( vOut, pName ?
atof(pName) : 1 );
1601 Vec_StrPutF_( vOut, pName ?
atof(pName) : 0 );
1606 Vec_StrPutI_( vOut, nOutputs );
1607 Vec_StrPut_( vOut );
1608 Vec_StrPut_( vOut );
1611 vNameIns = Vec_PtrAlloc( 16 );
1614 float CapOne, CapRise, CapFall;
1619 Vec_PtrPush( vNameIns, Abc_UtilStrsav(pName) );
1620 Vec_StrPutS_( vOut, pName );
1628 Vec_StrPutF_( vOut, CapRise );
1629 Vec_StrPutF_( vOut, CapFall );
1630 Vec_StrPut_( vOut );
1632 Vec_StrPut_( vOut );
1642 Vec_StrPutS_( vOut, pName );
1645 Vec_StrPutI_( vOut, Vec_PtrSize(vNameIns) );
1647 Vec_StrPutS_( vOut, pFormula );
1650 if ( vTruth == NULL )
1652 for ( i = 0; i < Abc_Truth6WordNum(Vec_PtrSize(vNameIns)); i++ )
1653 Vec_StrPutW_( vOut, Vec_WrdEntry(vTruth, i) );
1654 Vec_WrdFree( vTruth );
1655 Vec_StrPut_( vOut );
1656 Vec_StrPut_( vOut );
1659 if ( fUseFirstTable )
1664 Vec_StrPutS_( vOut, pName );
1665 Vec_StrPutI_( vOut, (
int)(pTiming != NULL) );
1666 if ( pTiming == NULL )
1669 Vec_StrPut_( vOut );
1670 Vec_StrPut_( vOut );
1674 { printf(
"Table cannot be found\n" );
return NULL; }
1677 { printf(
"Table cannot be found\n" );
return NULL; }
1680 { printf(
"Table cannot be found\n" );
return NULL; }
1683 { printf(
"Table cannot be found\n" );
return NULL; }
1694 Vec_StrPutS_( vOut, pName );
1695 Vec_StrPutI_( vOut, (
int)(Vec_PtrSize(vTimings) != 0) );
1696 if ( Vec_PtrSize(vTimings) == 0 )
1698 Vec_PtrFree( vTimings );
1702 Vec_StrPut_( vOut );
1703 Vec_StrPut_( vOut );
1705 for ( k = 0; k < 4; k++ )
1706 vTables[k] = Vec_PtrAlloc( 16 );
1712 { printf(
"Table cannot be found\n" );
return NULL; }
1715 { printf(
"Table cannot be found\n" );
return NULL; }
1718 { printf(
"Table cannot be found\n" );
return NULL; }
1721 { printf(
"Table cannot be found\n" );
return NULL; }
1723 Vec_PtrFree( vTimings );
1725 for ( k = 0; k < 4; k++ )
1729 { printf(
"Table indexes have different values\n" );
return NULL; }
1732 Vec_FltFree( vInd0 );
1733 Vec_FltFree( vInd1 );
1734 Vec_FltFree( vValues );
1738 Vec_StrPut_( vOut );
1739 Vec_PtrFreeFree( vNameIns );
1745 assert( Vec_PtrSize(vTemples) % 4 == 0 );
1748 if ( vArray == NULL )
1752 else if ( i % 4 == 2 || i % 4 == 3 )
1753 Vec_FltFree( vArray );
1755 Vec_PtrFree( vTemples );
1759 printf(
"Library \"%s\" from \"%s\" has %d cells ",
1761 printf(
"(%d skipped: %d seq; %d tri-state; %d no func; %d dont_use; %d with 2 outputs; %d with 3+ outputs). ",
1762 nSkipped[0]+nSkipped[1]+nSkipped[2]+nSkipped[3]+nSkipped[4]+nSkipped[5],
1763 nSkipped[0],nSkipped[1],nSkipped[2],nSkipped[3],nSkipped[5],nSkipped[4] );
1764 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
1786 pLib->
pFileName = Abc_UtilStrsav( pFileName );
1788 Vec_StrFree( vStr );
1806 char * pFileName =
"bwrc.lib";
1808 int fVeryVerbose = 0;
1819 Vec_StrFree( vStr );
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Vec_Str_t_ Vec_Str_t
ABC_NAMESPACE_IMPL_START int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(const char *path, const char *mode)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
unsigned __int64 word
DECLARATIONS ///.
Vec_Wrd_t * Mio_ParseFormulaTruth(char *pFormInit, char **ppVarNames, int nVars)
struct SC_DontUse_ SC_DontUse
SC_Lib * Abc_SclReadFromStr(Vec_Str_t *vOut)
void Abc_SclLibNormalize(SC_Lib *p)
#define ABC_SCL_CUR_VERSION
INCLUDES ///.
char * Scl_LibertyReadDefaultWireLoad(Scl_Tree_t *p)
void Scl_LibertyReadLoadUnit(Scl_Tree_t *p, Vec_Str_t *vOut)
#define Scl_ItemForEachChildName(p, pItem, pChild, pName)
void Scl_LibertyReadWireLoad(Scl_Tree_t *p, Vec_Str_t *vOut)
Vec_Ptr_t * Scl_LibertyReadTemplates(Scl_Tree_t *p)
void Scl_LibertyFixFileName(char *pFileName)
Vec_Flt_t * Scl_LibertyReadFloatVec(char *pName)
int Scl_LibertyReadTable(Scl_Tree_t *p, Vec_Str_t *vOut, Scl_Item_t *pTiming, char *pName, Vec_Ptr_t *vTemples)
int Scl_LibertyReadCellIsThreeState(Scl_Tree_t *p, Scl_Item_t *pCell)
void Scl_LibertyStringDump(char *pFileName, Vec_Str_t *vStr)
Vec_Str_t * Scl_LibertyReadGenlibStr(Scl_Tree_t *p, int fVerbose, SC_DontUse dont_use)
Scl_Item_t * Scl_LibertyReadPinTiming(Scl_Tree_t *p, Scl_Item_t *pPinOut, char *pNameIn)
int Scl_LibertyParseDump(Scl_Tree_t *p, char *pFileName)
void Scl_LibertyDumpTables(Vec_Str_t *vOut, Vec_Flt_t *vInd1, Vec_Flt_t *vInd2, Vec_Flt_t *vValues)
int Scl_LibertyReadTimeUnit(Scl_Tree_t *p)
void Scl_LibertyPrintTemplates(Vec_Ptr_t *vRes)
long Scl_LibertyItemNum(Scl_Tree_t *p, Scl_Item_t *pRoot, char *pName)
#define Scl_ItemForEachChild(p, pItem, pChild)
char * Scl_LibertyReadString(Scl_Tree_t *p, Scl_Pair_t Pair)
long Scl_LibertyBuildItem(Scl_Tree_t *p, char **ppPos, char *pEnd)
int Scl_LibertyScanTable(Scl_Tree_t *p, Vec_Ptr_t *vOut, Scl_Item_t *pTiming, char *pName, Vec_Ptr_t *vTemples)
char * Scl_LibertyFileContents(char *pFileName, long *nContents)
struct Scl_Pair_t_ Scl_Pair_t
void Scl_LibertyReadWireLoadSelect(Scl_Tree_t *p, Vec_Str_t *vOut)
char * Scl_LibertyReadDefaultWireLoadSel(Scl_Tree_t *p)
float Scl_LibertyReadPinCap(Scl_Tree_t *p, Scl_Item_t *pPin, char *pName)
Scl_LibertyType_t
DECLARATIONS ///.
int Scl_LibertyReadPinDirection(Scl_Tree_t *p, Scl_Item_t *pPin)
Vec_Ptr_t * Scl_LibertyReadPinTimingAll(Scl_Tree_t *p, Scl_Item_t *pPinOut, char *pNameIn)
long Scl_LibertyFileSize(char *pFileName)
char * Scl_LibertyReadPinFormula(Scl_Tree_t *p, Scl_Item_t *pPin)
void Scl_LibertyWipeOutComments(char *pBeg, char *pEnd)
long Scl_LibertyReadCellOutputNum(Scl_Tree_t *p, Scl_Item_t *pCell)
void Scl_LibertyStop(Scl_Tree_t *p, int fVerbose)
struct Scl_Item_t_ Scl_Item_t
int Scl_LibertyComputeWorstCase(Vec_Ptr_t *vTables, Vec_Flt_t **pvInd0, Vec_Flt_t **pvInd1, Vec_Flt_t **pvValues)
int Scl_LibertyReadDeriveStrength(Scl_Tree_t *p, Scl_Item_t *pCell)
Scl_Tree_t * Scl_LibertyStart(char *pFileName)
void Scl_LibertyParseDumpItem(FILE *pFile, Scl_Tree_t *p, Scl_Item_t *pItem, int nOffset)
FUNCTION DEFINITIONS ///.
char * Scl_LibertyReadCellArea(Scl_Tree_t *p, Scl_Item_t *pCell)
int Scl_LibertyReadCellIsDontUse(Scl_Tree_t *p, Scl_Item_t *pCell, SC_DontUse dont_use)
Scl_Tree_t * Scl_LibertyParse(char *pFileName, int fVerbose)
long Scl_LibertyCountItems(char *pBeg, char *pEnd)
int Scl_LibertyReadTimingSense(Scl_Tree_t *p, Scl_Item_t *pPin)
struct Scl_Tree_t_ Scl_Tree_t
Vec_Str_t * Scl_LibertyReadSclStr(Scl_Tree_t *p, int fVerbose, int fVeryVerbose, SC_DontUse dont_use, int fSkipMultiOuts)
char * Scl_LibertyReadCellLeakage(Scl_Tree_t *p, Scl_Item_t *pCell)
int Scl_LibertyReadCellIsFlop(Scl_Tree_t *p, Scl_Item_t *pCell)
float Scl_LibertyReadDefaultMaxTrans(Scl_Tree_t *p)
SC_Lib * Abc_SclReadLiberty(char *pFileName, int fVerbose, int fVeryVerbose, SC_DontUse dont_use, int fSkipMultiOuts)
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.