32 #define ABC_MAX_LIB_STR_LEN 5000
79 static inline void Scl_PrintSpace( FILE * pFile,
int nOffset ) {
int i;
for ( i = 0; i < nOffset; i++ ) fputc(
' ', pFile); }
82 #define Scl_ItemForEachChild( p, pItem, pChild ) \
83 for ( pChild = Scl_LibertyItem(p, pItem->Child); pChild; pChild = Scl_LibertyItem(p, pChild->Next) )
84 #define Scl_ItemForEachChildName( p, pItem, pChild, pName ) \
85 for ( pChild = Scl_LibertyItem(p, pItem->Child); pChild; pChild = Scl_LibertyItem(p, pChild->Next) ) if ( Scl_LibertyCompare(p, pChild->Key, pName) ) {} else
108 fprintf( pFile,
"(" );
110 fprintf( pFile,
") {\n" );
114 fprintf( pFile,
"}\n" );
120 fprintf( pFile,
" : " );
122 fprintf( pFile,
";\n" );
128 fprintf( pFile,
"(" );
130 fprintf( pFile,
");\n" );
139 if ( pFileName == NULL )
143 pFile = fopen( pFileName,
"w" );
146 printf(
"Scl_LibertyParseDump(): The output file is unavailable (absent or open).\n" );
151 if ( pFile != stdout )
171 for ( ; pBeg < pEnd; pBeg++ )
172 Counter += (*pBeg ==
'(' || *pBeg ==
':');
193 char * pCur, * pStart;
194 for ( pCur = pBeg; pCur < pEnd-1; pCur++ )
195 if ( pCur[0] ==
'/' && pCur[1] ==
'*' )
197 for ( pStart = pCur; pCur < pEnd-1; pCur++ )
198 if ( pCur[0] ==
'*' && pCur[1] ==
'/' )
200 for ( ; pStart < pCur + 2; pStart++ )
201 if ( *pStart !=
'\n' ) *pStart =
' ';
205 else if ( pCur[0] ==
'/' && pCur[1] ==
'/' )
207 for ( pStart = pCur; pCur < pEnd; pCur++ )
208 if ( pCur[0] ==
'\n' || pCur == pEnd-1 )
210 for ( ; pStart < pCur; pStart++ ) *pStart =
' ';
217 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' || c ==
'\\';
221 char * pPos = *ppPos;
222 for ( ; pPos < pEnd; pPos++ )
227 if ( fStopAtNewLine )
239 char * pPos = *ppPos;
242 for ( pPos++; pPos < pEnd; pPos++ )
251 for ( ; pPos < pEnd; pPos++ )
252 if ( *pPos ==
' ' || *pPos ==
'\r' || *pPos ==
'\n' || *pPos ==
'\t' ||
253 *pPos ==
':' || *pPos ==
';' ||
254 *pPos ==
'(' || *pPos ==
')' ||
255 *pPos ==
'{' || *pPos ==
'}' )
265 assert( *pPos ==
'(' || *pPos ==
'{' );
268 for ( ; pPos < pEnd; pPos++ )
280 for ( ; pPos < pEnd; pPos++ )
290 assert( *pPos ==
')' || *pPos ==
'}' );
299 char * pFirstNonSpace = NULL;
300 char * pLastNonSpace = NULL;
302 for ( pChar = pBeg; pChar < pEnd; pChar++ )
304 if ( *pChar ==
'\n' )
308 pLastNonSpace = pChar;
309 if ( pFirstNonSpace == NULL )
310 pFirstNonSpace = pChar;
312 if ( pFirstNonSpace == NULL || pLastNonSpace == NULL )
314 assert( pFirstNonSpace && pLastNonSpace );
346 if ( Pair.
Beg < Pair.
End && Buffer[0] ==
'\"' )
349 Buffer[Pair.
End-Pair.
Beg-1] = 0;
352 Buffer[Pair.
End-Pair.
Beg] = 0;
379 char * pNext, * pStop;
402 if ( *pNext !=
';' && *pNext !=
'\n' )
410 if ( pItem->
Next == -1 )
441 if ( pItem->
Child == -1 )
445 if ( pItem->
Next == -1 )
456 if ( pItem->
Next == -1 )
464 sprintf( p->
pError,
"File \"%s\". Line %6d. Failed to parse entry \"%s\".\n",
484 for ( pHead = pFileName; *pHead; pHead++ )
492 pFile = fopen( pFileName,
"rb" );
495 printf(
"Scl_LibertyFileSize(): The input file is unavailable (absent or open).\n" );
499 nFileSize = ftell( pFile );
505 FILE * pFile = fopen( pFileName,
"rb" );
506 char * pContents =
ABC_ALLOC(
char, nContents+1 );
508 RetValue = fread( pContents, nContents, 1, pFile );
510 pContents[nContents] = 0;
515 FILE * pFile = fopen( pFileName,
"wb" );
519 printf(
"Scl_LibertyStringDump(): The output file is unavailable.\n" );
584 printf(
"Parsing failed. " );
589 printf(
"Parsing finished successfully. " );
687 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped sequential cell \"%s\".\n",
Scl_LibertyReadString(p, pCell->
Head) );
692 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped three-state cell \"%s\".\n",
Scl_LibertyReadString(p, pCell->
Head) );
697 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" without logic function.\n",
Scl_LibertyReadString(p, pCell->
Head) );
707 if ( fVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" with constant formula \"%s\".\n",
Scl_LibertyReadString(p, pCell->
Head), pFormula );
815 if ( !
strcmp(pUnit,
"1ns") )
817 if ( !
strcmp(pUnit,
"100ps") )
819 if ( !
strcmp(pUnit,
"10ps") )
821 if ( !
strcmp(pUnit,
"1ps") )
825 printf(
"Libery parser cannot read \"time_unit\". Assuming time_unit : \"1ns\".\n" );
835 float First =
atof(
strtok(pHead,
" \t\n\r\\\","));
836 char * pSecond =
strtok(NULL,
" \t\n\r\\\",");
838 if ( pSecond && !
strcmp(pSecond,
"pf") )
840 else if ( pSecond && !
strcmp(pSecond,
"ff") )
845 printf(
"Libery parser cannot read \"capacitive_load_unit\". Assuming capacitive_load_unit(1, pf).\n" );
867 int First = atoi(
strtok(pHead,
" ,") );
893 char * pThird =
strtok(NULL,
" ");
894 if ( pThird[0] ==
'\"' )
918 if ( !
strcmp(pToken,
"input") )
920 if ( !
strcmp(pToken,
"output") )
959 if ( !
strcmp(pToken,
"positive_unate") )
961 if ( !
strcmp(pToken,
"negative_unate") )
963 if ( !
strcmp(pToken,
"non_unate") )
973 for ( pToken =
strtok(pName,
" \t\n\r\\\","); pToken; pToken =
strtok(NULL,
" \t\n\r\\\",") )
1002 for ( i = 0; i < 3; i++ )
1004 for ( i = 0; i < 4; i++ )
1006 for ( i = 0; i < 6; i++ )
1018 char * pThis, * pTempl = NULL;
1024 if ( pTable == NULL )
1028 if ( pTempl == NULL || pTempl[0] == 0 )
1040 if ( vIndex1 == NULL || vIndex2 == NULL || vValues == NULL )
1041 { printf(
"Incomplete table specification\n" );
return 0; }
1050 else if ( !
strcmp(pTempl,
"scalar") )
1065 { printf(
"Cannot read \"scalar\" template\n" );
return 0; }
1072 if ( i % 4 == 0 && !
strcmp(pTempl, pThis) )
1078 { printf(
"Template cannot be found in the template library\n" );
return 0; }
1096 vInd1 = vIndex1 ? vIndex1 : vInd1;
1097 vInd2 = vIndex2 ? vIndex2 : vInd2;
1108 vInd1 = vIndex2 ? vIndex2 : vInd1;
1109 vInd2 = vIndex1 ? vIndex1 : vInd2;
1138 if ( nTriples == 1 )
1149 for ( i = 1; i < nTriples; i++ )
1170 *pvValues = vValues;
1181 char * pThis, * pTempl = NULL;
1187 if ( pTable == NULL )
1191 if ( pTempl == NULL || pTempl[0] == 0 )
1203 if ( vIndex1 == NULL || vIndex2 == NULL || vValues == NULL )
1204 { printf(
"Incomplete table specification\n" );
return 0; }
1233 if ( i % 4 == 0 && !
strcmp(pTempl, pThis) )
1239 { printf(
"Template cannot be found in the template library\n" );
return 0; }
1257 vInd1 = vIndex1 ? vIndex1 : vInd1;
1258 vInd2 = vIndex2 ? vIndex2 : vInd2;
1283 vInd1 = vIndex2 ? vIndex2 : vInd1;
1284 vInd2 = vIndex1 ? vIndex1 : vInd2;
1310 for ( i = 0; i < 3; i++ )
1312 for ( i = 0; i < 4; i++ )
1314 for ( i = 0; i < 6; i++ )
1327 printf(
"There are %d slew/load templates\n",
Vec_PtrSize(vRes) % 4 );
1331 printf(
"%s\n", (
char *)vArray );
1332 else if ( i % 4 == 1 )
1333 printf(
"%d\n", (
int)(vArray != NULL) );
1334 else if ( i % 4 == 2 || i % 4 == 3 )
1345 char * pVar1, * pVar2;
1350 pVar1 = pVar2 = NULL;
1351 vIndex1 = vIndex2 = NULL;
1363 if ( pVar1 == NULL || pVar2 == NULL )
1371 assert( pVar1 != NULL && pVar2 != NULL );
1372 fFlag0 = (!
strcmp(pVar1,
"input_net_transition") && !
strcmp(pVar2,
"total_output_net_capacitance"));
1373 fFlag1 = (!
strcmp(pVar2,
"input_net_transition") && !
strcmp(pVar1,
"total_output_net_capacitance"));
1376 if ( !fFlag0 && !fFlag1 )
1383 Vec_PtrPush( vRes, fFlag0 ? NULL : (
void *)(ABC_PTRINT_T)1 );
1388 Abc_Print( 0,
"Templates are not defined.\n" );
1396 int fUseFirstTable = 0;
1398 Vec_Ptr_t * vNameIns, * vTemples = NULL;
1401 char * pFormula, * pName;
1402 int i, k,
Counter, nOutputs, nCells;
1403 int nSkipped[3] = {0};
1433 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped sequential cell \"%s\".\n",
Scl_LibertyReadString(p, pCell->
Head) );
1439 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped three-state cell \"%s\".\n",
Scl_LibertyReadString(p, pCell->
Head) );
1445 if ( fVeryVerbose ) printf(
"Scl_LibertyReadGenlib() skipped cell \"%s\" without logic function.\n",
Scl_LibertyReadString(p, pCell->
Head) );
1481 float CapOne, CapRise, CapFall;
1522 if ( fUseFirstTable )
1529 if ( pTiming == NULL )
1537 { printf(
"Table cannot be found\n" );
return NULL; }
1540 { printf(
"Table cannot be found\n" );
return NULL; }
1543 { printf(
"Table cannot be found\n" );
return NULL; }
1546 { printf(
"Table cannot be found\n" );
return NULL; }
1568 for ( k = 0; k < 4; k++ )
1575 { printf(
"Table cannot be found\n" );
return NULL; }
1578 { printf(
"Table cannot be found\n" );
return NULL; }
1581 { printf(
"Table cannot be found\n" );
return NULL; }
1584 { printf(
"Table cannot be found\n" );
return NULL; }
1588 for ( k = 0; k < 4; k++ )
1592 { printf(
"Table indexes have different values\n" );
return NULL; }
1612 else if ( i % 4 == 2 || i % 4 == 3 )
1618 printf(
"Library \"%s\" from \"%s\" has %d cells ",
1620 printf(
"(%d skipped: %d seq; %d tri-state; %d no func). ",
1621 nSkipped[0]+nSkipped[1]+nSkipped[2], nSkipped[0], nSkipped[1], nSkipped[2] );
1664 char * pFileName =
"bwrc.lib";
1666 int fVeryVerbose = 0;
static Scl_Item_t * Scl_LibertyRoot(Scl_Tree_t *p)
void Scl_LibertyReadWireLoadSelect(Scl_Tree_t *p, Vec_Str_t *vOut)
int Scl_LibertyCountItems(char *pBeg, char *pEnd)
int Scl_LibertyReadTable(Scl_Tree_t *p, Vec_Str_t *vOut, Scl_Item_t *pTiming, char *pName, Vec_Ptr_t *vTemples)
static int Scl_LibertyCompare(Scl_Tree_t *p, Scl_Pair_t Pair, char *pStr)
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
static void Vec_StrPutI_(Vec_Str_t *vOut, int Val)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
static void Vec_StrPutW_(Vec_Str_t *vOut, word Val)
void Scl_LibertyFixFileName(char *pFileName)
int Scl_LibertyReadDeriveStrength(Scl_Tree_t *p, Scl_Item_t *pCell)
static void Vec_FltWriteEntry(Vec_Flt_t *p, int i, float Entry)
static Vec_Flt_t * Vec_FltDup(Vec_Flt_t *pVec)
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
static int Scl_LibertyItemId(Scl_Tree_t *p, Scl_Item_t *pItem)
static void Vec_StrPutW(Vec_Str_t *vOut, word Val)
static char * Vec_StrArray(Vec_Str_t *p)
void Scl_LibertyPrintTemplates(Vec_Ptr_t *vRes)
char * Scl_LibertyReadCellArea(Scl_Tree_t *p, Scl_Item_t *pCell)
static int Abc_Truth6WordNum(int nVars)
static void Vec_FltFree(Vec_Flt_t *p)
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Vec_Str_t * Scl_LibertyReadSclStr(Scl_Tree_t *p, int fVerbose, int fVeryVerbose)
Vec_Wrd_t * Mio_ParseFormulaTruth(char *pFormInit, char **ppVarNames, int nVars)
Scl_Tree_t * Scl_LibertyStart(char *pFileName)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
static Vec_Flt_t * Vec_FltAlloc(int nCap)
FUNCTION DEFINITIONS ///.
#define ABC_ALLOC(type, num)
float Scl_LibertyReadPinCap(Scl_Tree_t *p, Scl_Item_t *pPin, char *pName)
char * Scl_LibertyReadDefaultWireLoadSel(Scl_Tree_t *p)
static Vec_Str_t * Vec_StrAlloc(int nCap)
Vec_Flt_t * Scl_LibertyReadFloatVec(char *pName)
static abctime Abc_Clock()
static void Vec_StrPush(Vec_Str_t *p, char Entry)
static int Vec_PtrSize(Vec_Ptr_t *p)
static void Vec_VecFree(Vec_Vec_t *p)
static void Vec_FltFreeP(Vec_Flt_t **p)
static void Vec_FltPush(Vec_Flt_t *p, float Entry)
static int Vec_FltEqual(Vec_Flt_t *p1, Vec_Flt_t *p2)
int Scl_LibertyParseDump(Scl_Tree_t *p, char *pFileName)
int Scl_LibertyReadTimingSense(Scl_Tree_t *p, Scl_Item_t *pPin)
#define ABC_MAX_LIB_STR_LEN
DECLARATIONS ///.
static void Abc_PrintTime(int level, const char *pStr, abctime time)
static void Vec_StrPutF_(Vec_Str_t *vOut, float Val)
static void Vec_FltPrint(Vec_Flt_t *vVec)
static Vec_Int_t * Vec_IntStart(int nSize)
int Scl_LibertyReadCellIsThreeState(Scl_Tree_t *p, Scl_Item_t *pCell)
static void Scl_PrintWord(FILE *pFile, Scl_Tree_t *p, Scl_Pair_t Pair)
int Scl_LibertyReadCellOutputNum(Scl_Tree_t *p, Scl_Item_t *pCell)
Vec_Str_t * Scl_LibertyParseGenlibStr(char *pFileName, int fVerbose)
static void Vec_StrFree(Vec_Str_t *p)
SC_Lib * Abc_SclReadFromStr(Vec_Str_t *vOut)
void Scl_LibertyReadLoadUnit(Scl_Tree_t *p, Vec_Str_t *vOut)
unsigned __int64 word
DECLARATIONS ///.
void Scl_LibertyReadWireLoad(Scl_Tree_t *p, Vec_Str_t *vOut)
#define ABC_NAMESPACE_IMPL_END
static void Vec_WrdFree(Vec_Wrd_t *p)
static Scl_Pair_t Scl_LibertyUpdateHead(Scl_Tree_t *p, Scl_Pair_t Head)
static void Vec_StrPutS_(Vec_Str_t *vOut, char *Val)
static void Vec_StrPutS(Vec_Str_t *vOut, char *pStr)
void Scl_LibertyWipeOutComments(char *pBeg, char *pEnd)
int Scl_LibertyReadCellIsFlop(Scl_Tree_t *p, Scl_Item_t *pCell)
float Scl_LibertyReadDefaultMaxTrans(Scl_Tree_t *p)
Vec_Ptr_t * Scl_LibertyReadTemplates(Scl_Tree_t *p)
#define Scl_ItemForEachChild(p, pItem, pChild)
static void Abc_Print(int level, const char *format,...)
void Scl_LibertyParseDumpItem(FILE *pFile, Scl_Tree_t *p, Scl_Item_t *pItem, int nOffset)
FUNCTION DEFINITIONS ///.
static void Vec_StrPutF(Vec_Str_t *vOut, float Val)
Scl_Item_t * Scl_LibertyReadPinTiming(Scl_Tree_t *p, Scl_Item_t *pPinOut, char *pNameIn)
#define ABC_NAMESPACE_IMPL_START
#define ABC_SCL_CUR_VERSION
INCLUDES ///.
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
static int Vec_StrSize(Vec_Str_t *p)
int Scl_LibertyReadTimeUnit(Scl_Tree_t *p)
int Scl_LibertyComputeWorstCase(Vec_Ptr_t *vTables, Vec_Flt_t **pvInd0, Vec_Flt_t **pvInd1, Vec_Flt_t **pvValues)
char * Scl_LibertyReadPinFormula(Scl_Tree_t *p, Scl_Item_t *pPin)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
int Scl_LibertyReadPinDirection(Scl_Tree_t *p, Scl_Item_t *pPin)
Scl_Tree_t * Scl_LibertyParse(char *pFileName, int fVerbose)
void Scl_LibertyStringDump(char *pFileName, Vec_Str_t *vStr)
int Scl_LibertyFileSize(char *pFileName)
char * Scl_LibertyReadCellLeakage(Scl_Tree_t *p, Scl_Item_t *pCell)
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
static void Vec_StrPutI(Vec_Str_t *vOut, int Val)
#define ABC_CALLOC(type, num)
static void Vec_StrPut_(Vec_Str_t *vOut)
char * Scl_LibertyFileContents(char *pFileName, int nContents)
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
char * Scl_LibertyReadDefaultWireLoad(Scl_Tree_t *p)
#define Scl_ItemForEachChildName(p, pItem, pChild, pName)
int Scl_LibertyItemNum(Scl_Tree_t *p, Scl_Item_t *pRoot, char *pName)
int Scl_LibertyScanTable(Scl_Tree_t *p, Vec_Ptr_t *vOut, Scl_Item_t *pTiming, char *pName, Vec_Ptr_t *vTemples)
static int Scl_LibertyCharIsSpace(char c)
static void Vec_StrPrintStr(Vec_Str_t *p, const char *pStr)
static float Vec_FltEntry(Vec_Flt_t *p, int i)
void Scl_LibertyStop(Scl_Tree_t *p, int fVerbose)
static void Scl_PrintSpace(FILE *pFile, int nOffset)
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
char * Scl_LibertyReadString(Scl_Tree_t *p, Scl_Pair_t Pair)
void Abc_SclLibNormalize(SC_Lib *p)
static int Vec_FltSize(Vec_Flt_t *p)
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
char * Abc_UtilStrsav(char *s)
SC_Lib * Abc_SclReadLiberty(char *pFileName, int fVerbose, int fVeryVerbose)
static Scl_Item_t * Scl_LibertyItem(Scl_Tree_t *p, int v)
static void ** Vec_PtrArray(Vec_Ptr_t *p)
static int Scl_LibertySkipEntry(char **ppPos, char *pEnd)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
static int Scl_LibertySkipSpaces(Scl_Tree_t *p, char **ppPos, char *pEnd, int fStopAtNewLine)
static char * Scl_LibertyFindMatch(char *pPos, char *pEnd)
Vec_Str_t * Scl_LibertyReadGenlibStr(Scl_Tree_t *p, int fVerbose)
static Scl_Item_t * Scl_LibertyNewItem(Scl_Tree_t *p, int Type)
int Scl_LibertyBuildItem(Scl_Tree_t *p, char **ppPos, char *pEnd)
Vec_Ptr_t * Scl_LibertyReadPinTimingAll(Scl_Tree_t *p, Scl_Item_t *pPinOut, char *pNameIn)
void Scl_LibertyDumpTables(Vec_Str_t *vOut, Vec_Flt_t *vInd1, Vec_Flt_t *vInd2, Vec_Flt_t *vValues)
static void Vec_PtrFree(Vec_Ptr_t *p)