diff options
Diffstat (limited to 'src/readliberty.c')
-rw-r--r-- | src/readliberty.c | 91 |
1 files changed, 70 insertions, 21 deletions
diff --git a/src/readliberty.c b/src/readliberty.c index 079a644..4505480 100644 --- a/src/readliberty.c +++ b/src/readliberty.c @@ -167,6 +167,7 @@ advancetoken(FILE *flib, char delimiter) // Remove any trailing whitespace tptr = token + strlen(token) - 1; + if (tptr < token) tptr = token; while (isblank(*tptr)) { *tptr = '\0'; tptr--; @@ -650,16 +651,24 @@ read_liberty(char *libfile, char *pattern) newtable->invert = 1; } else if (!strcasecmp(token, "index_1")) { + char dnum = ','; + token = advancetoken(flib, 0); // Open parens token = advancetoken(flib, 0); // Quote if (!strcmp(token, "\"")) token = advancetoken(flib, '\"'); + iptr = token; + + // Check if table is comma or space separated + if (strchr(iptr, dnum) == NULL) + if (strchr(iptr, ' ') != NULL) + dnum = ' '; + if (newtable->invert == 1) { // Count entries - iptr = token; newtable->csize = 1; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->csize++; } @@ -669,7 +678,7 @@ read_liberty(char *libfile, char *pattern) iptr = token; sscanf(iptr, "%lg", &newtable->caps[0]); newtable->caps[0] *= cap_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->csize++; sscanf(iptr, "%lg", @@ -679,10 +688,10 @@ read_liberty(char *libfile, char *pattern) newtable->csize++; } else { // newtable->invert = 0 + // Count entries - iptr = token; newtable->tsize = 1; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->tsize++; } @@ -692,7 +701,7 @@ read_liberty(char *libfile, char *pattern) iptr = token; sscanf(iptr, "%lg", &newtable->times[0]); newtable->times[0] *= time_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->tsize++; sscanf(iptr, "%lg", @@ -705,16 +714,26 @@ read_liberty(char *libfile, char *pattern) token = advancetoken(flib, ';'); // EOL semicolon } else if (!strcasecmp(token, "index_2")) { + char dnum = ','; + token = advancetoken(flib, 0); // Open parens token = advancetoken(flib, 0); // Quote if (!strcmp(token, "\"")) token = advancetoken(flib, '\"'); + // Determine if array tokens are comma or space separated. + iptr = token; + + // Check if table is comma or space separated + if (strchr(iptr, dnum) == NULL) + if (strchr(iptr, ' ') != NULL) + dnum = ' '; + if (newtable->invert == 0) { + // Count entries - iptr = token; newtable->csize = 1; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->csize++; } @@ -724,7 +743,7 @@ read_liberty(char *libfile, char *pattern) iptr = token; sscanf(iptr, "%lg", &newtable->caps[0]); newtable->caps[0] *= cap_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->csize++; sscanf(iptr, "%lg", @@ -735,9 +754,8 @@ read_liberty(char *libfile, char *pattern) } else { // newtable->invert == 1 // Count entries - iptr = token; newtable->tsize = 1; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->tsize++; } @@ -747,7 +765,7 @@ read_liberty(char *libfile, char *pattern) iptr = token; sscanf(iptr, "%lg", &newtable->times[0]); newtable->times[0] *= time_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; newtable->tsize++; sscanf(iptr, "%lg", @@ -1152,6 +1170,7 @@ read_liberty(char *libfile, char *pattern) while (*token != '}') { token = advancetoken(flib, 0); if (!strcasecmp(token, "index_1")) { + char dnum = ','; // Local index values override those in the template @@ -1162,15 +1181,21 @@ read_liberty(char *libfile, char *pattern) //------------------------- + iptr = token; + + // Check if table is comma or space separated + if (strchr(iptr, dnum) == NULL) + if (strchr(iptr, ' ') != NULL) + dnum = ' '; + if (reftable && (reftable->invert == 1)) { // Entries had better match the ref table - iptr = token; i = 0; newcell->caps = (double *)malloc(reftable->csize * sizeof(double)); sscanf(iptr, "%lg", &newcell->caps[0]); newcell->caps[0] *= cap_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; i++; sscanf(iptr, "%lg", &newcell->caps[i]); @@ -1178,13 +1203,12 @@ read_liberty(char *libfile, char *pattern) } } else if (reftable && (reftable->invert == 0)) { - iptr = token; i = 0; newcell->times = (double *)malloc(reftable->tsize * sizeof(double)); sscanf(iptr, "%lg", &newcell->times[0]); newcell->times[0] *= time_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; i++; if (i < reftable->tsize) { @@ -1201,6 +1225,7 @@ read_liberty(char *libfile, char *pattern) token = advancetoken(flib, ';'); // EOL semicolon } else if (!strcasecmp(token, "index_2")) { + char dnum = ','; // Local index values override those in the template @@ -1211,15 +1236,21 @@ read_liberty(char *libfile, char *pattern) //------------------------- + iptr = token; + + // Check if table is comma or space separated + if (strchr(iptr, dnum) == NULL) + if (strchr(iptr, ' ') != NULL) + dnum = ' '; + if (reftable && (reftable->invert == 1)) { // Entries had better match the ref table - iptr = token; i = 0; newcell->times = (double *)malloc(reftable->tsize * sizeof(double)); sscanf(iptr, "%lg", &newcell->times[0]); newcell->times[0] *= time_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; i++; sscanf(iptr, "%lg", &newcell->times[i]); @@ -1227,13 +1258,12 @@ read_liberty(char *libfile, char *pattern) } } else if (reftable && (reftable->invert == 0)) { - iptr = token; i = 0; newcell->caps = (double *)malloc(reftable->csize * sizeof(double)); sscanf(iptr, "%lg", &newcell->caps[0]); newcell->caps[0] *= cap_unit; - while ((iptr = strchr(iptr, ',')) != NULL) { + while ((iptr = strchr(iptr, dnum)) != NULL) { iptr++; i++; if (i < reftable->csize) { @@ -1274,6 +1304,7 @@ read_liberty(char *libfile, char *pattern) *(newcell->values + j * reftable->tsize + i) = gval * time_unit; while (*iptr != ' ' && *iptr != '\"' && + *iptr != '\0' && *iptr != ',' || *iptr == '\\') iptr++; } @@ -1390,7 +1421,12 @@ get_values(Cell *curcell, double *retdelay, double *retcap) // Calculate delay per load. Note that cap at this point should be // in fF, and trise should be in ps. // So the value of loaddelay is in ps/fF. - loaddelay = (maxtrise - mintrise) / (maxcap - mincap); + // If there is only one cap value, then nothing can be calculated; set + // loaddelay to zero so it does not blow up to infinity. + if (maxcap == mincap) + loaddelay = 0.0; + else + loaddelay = (maxtrise - mintrise) / (maxcap - mincap); curcell->slope = loaddelay; curcell->mintrans = mintrise; @@ -1472,6 +1508,7 @@ Pin * get_pin_by_name(Cell *curcell, char *pinname) { Pin *curpin; + char *dptr; for (curpin = curcell->pins; curpin; curpin = curpin->next) { if (!strcmp(curpin->name, pinname)) { @@ -1479,6 +1516,18 @@ get_pin_by_name(Cell *curcell, char *pinname) return curpin; } } + /* Check for buses */ + for (curpin = curcell->pins; curpin; curpin = curpin->next) { + dptr = strchr(curpin->name, '['); + if (dptr != NULL) { + *dptr = '\0'; + if (!strcmp(curpin->name, pinname)) { + *dptr = '['; + return curpin; + } + *dptr = '['; + } + } return NULL; } |