1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518
|
/*
* lef.c --
*
* This module incorporates the LEF/DEF format for standard-cell routing
* route.
*
* Version 0.1 (September 26, 2003): LEF input handling. Includes creation
* of cells from macro statements, handling of pins, ports, obstructions, and
* associated geometry.
*
* Written by Tim Edwards, Open Circuit Design
* Modified June 2011 for use with qrouter.
*
* It is assumed that the "route.cfg" file has been called prior to this, and
* so the basic linked lists have been created. The contents of the LEF file
* will override anything in the route.cfg file, allowing the route.cfg file
* to contain a minimum of information, but also allowing for the possibility
* that there is no LEF file for the technology, and that all such information
* is in the route.cfg file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/time.h>
#include <math.h>
#include "qrouter.h"
#include "node.h"
#include "qconfig.h"
#include "maze.h"
#include "lef.h"
/* ---------------------------------------------------------------------*/
/* Current line number for reading */
int lefCurrentLine;
/* Information about routing layers */
LefList LefInfo;
/* Gate information is in the linked list GateInfo, imported */
/*---------------------------------------------------------
* Lookup --
* Searches a table of strings to find one that matches a given
* string. It's useful mostly for command lookup.
*
* Only the portion of a string in the table up to the first
* blank character is considered significant for matching.
*
* Results:
* If str is the same as
* or an unambiguous abbreviation for one of the entries
* in table, then the index of the matching entry is returned.
* If str is not the same as any entry in the table, but
* an abbreviation for more than one entry,
* then -1 is returned. If str doesn't match any entry, then
* -2 is returned. Case differences are ignored.
*
* NOTE:
* Table entries need no longer be in alphabetical order
* and they need not be lower case. The irouter command parsing
* depends on these features.
*
* Side Effects:
* None.
*---------------------------------------------------------
*/
int
Lookup(str, table)
char *str; /* Pointer to a string to be looked up */
char *(table[]); /* Pointer to an array of string pointers
* which are the valid commands.
* The end of
* the table is indicated by a NULL string.
*/
{
int match = -2; /* result, initialized to -2 = no match */
int pos;
int ststart = 0;
/* search for match */
for (pos=0; table[pos] != NULL; pos++)
{
char *tabc = table[pos];
char *strc = &(str[ststart]);
while (*strc!='\0' && *tabc!=' ' &&
((*tabc==*strc) ||
(isupper(*tabc) && islower(*strc) && (tolower(*tabc)== *strc))||
(islower(*tabc) && isupper(*strc) && (toupper(*tabc)== *strc)) ))
{
strc++;
tabc++;
}
if (*strc=='\0')
{
/* entry matches */
if(*tabc==' ' || *tabc=='\0')
{
/* exact match - record it and terminate search */
match = pos;
break;
}
else if (match == -2)
{
/* inexact match and no previous match - record this one
* and continue search */
match = pos;
}
else
{
/* previous match, so string is ambiguous unless exact
* match exists. Mark ambiguous for now, and continue
* search.
*/
match = -1;
}
}
}
return(match);
}
/*
* ----------------------------------------------------------------------------
* LookupFull --
*
* Look up a string in a table of pointers to strings. The last
* entry in the string table must be a NULL pointer.
* This is much simpler than Lookup() in that it does not
* allow abbreviations. It does, however, ignore case.
*
* Results:
* Index of the name supplied in the table, or -1 if the name
* is not found.
*
* Side effects:
* None.
*
* ----------------------------------------------------------------------------
*/
int
LookupFull(name, table)
char *name;
char **table;
{
char **tp;
for (tp = table; *tp; tp++)
{
if (strcmp(name, *tp) == 0)
return (tp - table);
else
{
char *sptr, *tptr;
for (sptr = name, tptr = *tp; ((*sptr != '\0') && (*tptr != '\0'));
sptr++, tptr++)
if (toupper(*sptr) != toupper(*tptr))
break;
if ((*sptr == '\0') && (*tptr == '\0'))
return (tp - table);
}
}
return (-1);
}
/*
*------------------------------------------------------------
*
* LefNextToken --
*
* Move to the next token in the stream input.
* If "ignore_eol" is FALSE, then the end-of-line character
* "\n" will be returned as a token when encountered.
* Otherwise, end-of-line will be ignored.
*
* Results:
* Pointer to next token to parse
*
* Side Effects:
* May read a new line from the specified file.
*
* Warnings:
* The return result of LefNextToken will be overwritten by
* subsequent calls to LefNextToken if more than one line of
* input is parsed.
*
*------------------------------------------------------------
*/
char *
LefNextToken(FILE *f, u_char ignore_eol)
{
static char line[LEF_LINE_MAX + 2]; /* input buffer */
static char *nexttoken = NULL; /* pointer to next token */
static char *curtoken; /* pointer to current token */
static char eol_token='\n';
/* Read a new line if necessary */
if (nexttoken == NULL)
{
for(;;)
{
if (fgets(line, LEF_LINE_MAX + 1, f) == NULL) return NULL;
lefCurrentLine++;
curtoken = line;
while (isspace(*curtoken) && (*curtoken != '\n') && (*curtoken != '\0'))
curtoken++; /* skip leading whitespace */
if ((*curtoken != '#') && (*curtoken != '\n') && (*curtoken != '\0'))
{
nexttoken = curtoken;
break;
}
}
if (!ignore_eol)
return &eol_token;
}
else
curtoken = nexttoken;
/* Find the next token; set to NULL if none (end-of-line). */
/* Treat quoted material as a single token */
if (*nexttoken == '\"') {
nexttoken++;
while (((*nexttoken != '\"') || (*(nexttoken - 1) == '\\')) &&
(*nexttoken != '\0')) {
if (*nexttoken == '\n') {
if (fgets(nexttoken + 1, LEF_LINE_MAX -
(size_t)(nexttoken - line), f) == NULL)
return NULL;
}
nexttoken++; /* skip all in quotes (move past current token) */
}
if (*nexttoken == '\"')
nexttoken++;
}
else {
while (!isspace(*nexttoken) && (*nexttoken != '\0') && (*nexttoken != '\n'))
nexttoken++; /* skip non-whitespace (move past current token) */
}
/* Terminate the current token */
if (*nexttoken != '\0') *nexttoken++ = '\0';
while (isspace(*nexttoken) && (*nexttoken != '\0') && (*nexttoken != '\n'))
nexttoken++; /* skip any whitespace */
if ((*nexttoken == '#') || (*nexttoken == '\n') || (*nexttoken == '\0'))
nexttoken = NULL;
return curtoken;
}
/*
*------------------------------------------------------------
*
* LefError --
*
* Print an error message (via fprintf) giving the line
* number of the input file on which the error occurred.
*
* Results:
* None.
*
* Side Effects:
* Prints to the output (stderr).
*
*------------------------------------------------------------
*/
void
LefError(char *fmt, ...)
{
static int errors = 0;
va_list args;
if (Verbose == 0) return;
if (fmt == NULL) /* Special case: report any errors and reset */
{
if (errors)
{
Fprintf(stdout, "LEF Read: encountered %d error%s total.\n",
errors, (errors == 1) ? "" : "s");
errors = 0;
}
return;
}
if (errors < LEF_MAX_ERRORS)
{
Fprintf(stderr, "LEF Read, Line %d: ", lefCurrentLine);
va_start(args, fmt);
Vprintf(stderr, fmt, args);
va_end(args);
Flush(stderr);
}
else if (errors == LEF_MAX_ERRORS)
Fprintf(stderr, "LEF Read: Further errors will not be reported.\n");
errors++;
}
/*
*------------------------------------------------------------
*
* LefParseEndStatement --
*
* Check if the string passed in "lineptr" contains the
* appropriate matching keyword. Sections in LEF files
* should end with "END (keyword)" or "END". To check
* against the latter case, "match" should be NULL.
*
* Results:
* TRUE if the line matches the expected end statement,
* FALSE if not.
*
* Side effects:
* None.
*
*------------------------------------------------------------
*/
u_char
LefParseEndStatement(FILE *f, char *match)
{
char *token;
int keyword, words;
char *match_name[2];
match_name[0] = match;
match_name[1] = NULL;
token = LefNextToken(f, (match == NULL) ? FALSE : TRUE);
if (token == NULL)
{
LefError("Bad file read while looking for END statement\n");
return FALSE;
}
/* END or ENDEXT */
if ((*token == '\n') && (match == NULL)) return TRUE;
/* END <section_name> */
else {
keyword = LookupFull(token, match_name);
if (keyword == 0)
return TRUE;
else
return FALSE;
}
}
/*
*------------------------------------------------------------
*
* LefSkipSection --
*
* Skip to the "END" record of a LEF input section
* String "section" must follow the "END" statement in
* the file to be considered a match; however, if
* section = NULL, then "END" must have no strings
* following.
*
* Results:
* None.
*
* Side Effects:
* Reads input from the specified file. Prints an
* error message if the expected END record cannot
* be found.
*
*------------------------------------------------------------
*/
void
LefSkipSection(FILE *f, char *section)
{
char *token;
int keyword;
static char *end_section[] = {
"END",
"ENDEXT",
NULL
};
while ((token = LefNextToken(f, TRUE)) != NULL)
{
if ((keyword = Lookup(token, end_section)) == 0)
{
if (LefParseEndStatement(f, section))
return;
}
else if (keyword == 1)
{
if (!strcmp(section, "BEGINEXT"))
return;
}
}
LefError("Section %s has no END record!\n", section);
return;
}
/*
*------------------------------------------------------------
*
* lefFindCell --
*
* "name" is the name of the cell to search for.
* Returns the GATE entry for the cell from the GateInfo
* list.
*
*------------------------------------------------------------
*/
GATE
lefFindCell(char *name)
{
GATE gateginfo;
for (gateginfo = GateInfo; gateginfo; gateginfo = gateginfo->next) {
if (!strcasecmp(gateginfo->gatename, name))
return gateginfo;
}
return (GATE)NULL;
}
/*
*------------------------------------------------------------
*
* LefLower --
*
* Convert a token in a LEF or DEF file to all-lowercase.
*
*------------------------------------------------------------
*/
char *
LefLower(char *token)
{
char *tptr;
for (tptr = token; *tptr != '\0'; tptr++)
*tptr = tolower(*tptr);
return token;
}
/*
*------------------------------------------------------------
* LefRedefined --
*
* In preparation for redefining a LEF layer, we need
* to first check if there are multiple names associated
* with the lefLayer entry. If so, split the entry into
* two copies, so that the redefinition doesn't affect
* the other LEF names.
*
* Results:
* Pointer to a lefLayer, which may or may not be the
* same one presented to the subroutine.
*
* Side Effects:
* May add an entry to the list of LEF layers.
*
*------------------------------------------------------------
*/
LefList
LefRedefined(LefList lefl, char *redefname)
{
LefList slef, newlefl;
char *altName;
int records;
DSEG drect;
/* check if more than one entry points to the same */
/* lefLayer record. If so, we will also record the */
/* name of the first type that is not the same as */
/* "redefname". */
records = 0;
altName = NULL;
for (slef = LefInfo; slef; slef = slef->next) {
if (slef == lefl)
records++;
if (altName == NULL)
if (strcmp(slef->lefName, redefname))
altName = (char *)slef->lefName;
}
if (records == 1)
{
/* Only one name associated with the record, so */
/* just clear all the allocated information. */
while (lefl->info.via.lr) {
drect = lefl->info.via.lr->next;
free(lefl->info.via.lr);
lefl->info.via.lr = drect;
}
newlefl = lefl;
}
else
{
slef = LefFindLayer(redefname);
newlefl = (LefList)malloc(sizeof(lefLayer));
newlefl->lefName = strdup(newlefl->lefName);
newlefl->next = LefInfo;
LefInfo = newlefl;
/* If the canonical name of the original entry */
/* is "redefname", then change it. */
if (!strcmp(slef->lefName, redefname))
if (altName != NULL)
slef->lefName = altName;
}
newlefl->type = -1;
newlefl->obsType = -1;
newlefl->info.via.area.x1 = 0.0;
newlefl->info.via.area.x2 = 0.0;
newlefl->info.via.area.y1 = 0.0;
newlefl->info.via.area.y2 = 0.0;
newlefl->info.via.area.layer = -1;
newlefl->info.via.cell = (GATE)NULL;
newlefl->info.via.lr = (DSEG)NULL;
return newlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers
*------------------------------------------------------------
*/
LefList
LefFindLayer(char *token)
{
LefList lefl, rlefl;
if (token == NULL) return NULL;
rlefl = (LefList)NULL;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (!strcmp(lefl->lefName, token)) {
rlefl = lefl;
break;
}
}
return rlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers, by layer number
*------------------------------------------------------------
*/
LefList
LefFindLayerByNum(int layer)
{
LefList lefl, rlefl;
rlefl = (LefList)NULL;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->type == layer) {
rlefl = lefl;
break;
}
}
return rlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers, and return the
* layer number.
*------------------------------------------------------------
*/
int
LefFindLayerNum(char *token)
{
LefList lefl;
lefl = LefFindLayer(token);
if (lefl)
return lefl->type;
else
return -1;
}
/*
*---------------------------------------------------------------
* Find the maximum routing layer number defined by the LEF file
*---------------------------------------------------------------
*/
int
LefGetMaxLayer()
{
int maxlayer = -1;
LefList lefl;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->type > maxlayer)
maxlayer = lefl->type;
}
return (maxlayer + 1);
}
/*
*------------------------------------------------------------
* Return the route keepout area, defined as the route space
* plus 1/2 the route width. This is the distance outward
* from an obstruction edge within which one cannot place a
* route.
*
* If no route layer is defined, then we pick up the value
* from information in the route.cfg file (if any). Here
* we define it as the route pitch less 1/2 the route width,
* which is the same as above if the route pitch has been
* chosen for minimum spacing.
*
* If all else fails, return zero.
*------------------------------------------------------------
*/
double
LefGetRouteKeepout(int layer)
{
LefList lefl;
double dist;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.width / 2.0
+ lefl->info.route.spacing->spacing;
}
}
return MIN(PitchX[layer], PitchY[layer]) - PathWidth[layer] / 2.0;
}
/*
*------------------------------------------------------------
* Similar routine to the above. Return the route width for
* a route layer. Return value in microns. If there is no
* LEF file information about the route width, then return
* half of the minimum route pitch.
*------------------------------------------------------------
*/
double
LefGetRouteWidth(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.width;
}
}
return MIN(PitchX[layer], PitchY[layer]) / 2.0;
}
/*
*------------------------------------------------------------
* Similar routine to the above. Return the route offset for
* a route layer. Return value in microns. If there is no
* LEF file information about the route offset, then return
* half of the minimum route pitch.
*------------------------------------------------------------
*/
double
LefGetRouteOffset(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.offset;
}
}
return MIN(PitchX[layer], PitchY[layer]) / 2.0;
}
/*
*------------------------------------------------------------
* Determine and return the width of a via. The first layer
* is the base (lower) layer of the via (e.g., layer 0, or
* metal1, for via12). The second layer is the layer for
* which we want the width rule (e.g., 0 or 1, for metal1
* or metal2). If dir = 0, return the side-to-side width,
* otherwise, return the top-to-bottom width. This accounts
* for non-square vias.
*
* Note that Via rectangles are stored with x2 dimensions
* because the center can be on a half-grid position; so,
* return half the value obtained.
*
* To-do: Differentiate between X and Y vias when doing
* checkerboard via patterning.
*------------------------------------------------------------
*/
double
LefGetViaWidth(int base, int layer, int dir)
{
DSEG lrect;
LefList lefl;
double width;
lefl = LefFindLayer(ViaX[base]);
if (!lefl) {
if (base == Num_layers)
lefl = LefFindLayer(ViaX[base - 1]);
}
if (lefl) {
if (lefl->lefClass == CLASS_VIA) {
if (lefl->info.via.area.layer == layer) {
if (dir)
width = lefl->info.via.area.y2 - lefl->info.via.area.y1;
else
width = lefl->info.via.area.x2 - lefl->info.via.area.x1;
return width / 2.0;
}
for (lrect = lefl->info.via.lr; lrect; lrect = lrect->next) {
if (lrect->layer == layer) {
if (dir)
width = lrect->y2 - lrect->y1;
else
width = lrect->x2 - lrect->x1;
return width / 2.0;
}
}
}
}
return MIN(PitchX[layer], PitchY[layer]) / 2.0; // Best guess
}
/*
*------------------------------------------------------------
* And another such routine, for route spacing (minimum width)
*------------------------------------------------------------
*/
double
LefGetRouteSpacing(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.spacing->spacing;
}
}
return MIN(PitchX[layer], PitchY[layer]) / 2.0;
}
/*
*------------------------------------------------------------
* Find route spacing to a metal layer of specific width
*------------------------------------------------------------
*/
double
LefGetRouteWideSpacing(int layer, double width)
{
LefList lefl;
lefSpacingRule *srule;
double spacing;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
// Prepare a default in case of bad values
spacing = lefl->info.route.spacing->spacing;
for (srule = lefl->info.route.spacing; srule; srule = srule->next) {
if (srule->width > width) break;
spacing = srule->spacing;
}
return spacing;
}
}
return MIN(PitchX[layer], PitchY[layer]) / 2.0;
}
/*
*------------------------------------------------------------
* Get the route pitch for a given layer
*------------------------------------------------------------
*/
double
LefGetRoutePitch(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.pitch;
}
}
return MIN(PitchX[layer], PitchY[layer]);
}
/*
*------------------------------------------------------------
* Get the route name for a given layer
*------------------------------------------------------------
*/
char *
LefGetRouteName(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->lefName;
}
}
return NULL;
}
/*
*------------------------------------------------------------
* Get the route orientation for the given layer,
* where the result is 1 for horizontal, 0 for vertical, and
* -1 if the layer is not found.
*------------------------------------------------------------
*/
int
LefGetRouteOrientation(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return (int)lefl->info.route.hdirection;
}
}
return -1;
}
/*
*------------------------------------------------------------
* LefReadLayers --
*
* Read a LEF "LAYER" record from the file.
* If "obstruct" is TRUE, returns the layer mapping
* for obstruction geometry as defined in the
* technology file (if it exists), and up to two
* types are returned (the second in the 3rd argument
* pointer).
*
* Results:
* Returns layer number or -1 if no matching type is found.
*
* Side Effects:
* Reads input from file f;
*
*------------------------------------------------------------
*/
int
LefReadLayers(f, obstruct, lreturn)
FILE *f;
u_char obstruct;
int *lreturn;
{
char *token;
int curlayer = -1;
LefList lefl = NULL;
token = LefNextToken(f, TRUE);
if (*token == ';')
{
LefError("Bad Layer statement\n");
return -1;
}
else
{
lefl = LefFindLayer(token);
if (lefl)
{
if (obstruct)
{
/* Use the obstruction type, if it is defined */
curlayer = lefl->obsType;
if ((curlayer < 0) && (lefl->lefClass != CLASS_IGNORE))
curlayer = lefl->type;
else if (lefl->lefClass == CLASS_VIA)
if (lreturn) *lreturn = lefl->info.via.obsType;
}
else
{
if (lefl->lefClass != CLASS_IGNORE)
curlayer = lefl->type;
}
}
if ((curlayer < 0) && ((!lefl) || (lefl->lefClass != CLASS_IGNORE)))
{
LefError("Don't know how to parse layer \"%s\"\n", token);
}
}
return curlayer;
}
/*
*------------------------------------------------------------
* LefReadLayer --
*
* Read a LEF "LAYER" record from the file.
* If "obstruct" is TRUE, returns the layer mapping
* for obstruction geometry as defined in the
* technology file (if it exists).
*
* Results:
* Returns a layer number or -1 if no match is found.
*
* Side Effects:
* Reads input from file f;
*
*------------------------------------------------------------
*/
int
LefReadLayer(FILE *f, u_char obstruct)
{
return LefReadLayers(f, obstruct, (int *)NULL);
}
/*
*------------------------------------------------------------
* LefReadRect --
*
* Read a LEF "RECT" record from the file, and
* return a Rect in micron coordinates.
*
* Results:
* Returns a pointer to a Rect containing the micron
* coordinates, or NULL if an error occurred.
*
* Side Effects:
* Reads input from file f;
*
* Note:
* LEF/DEF does NOT define a RECT record as having (...)
* pairs, only routes. However, at least one DEF file
* contains this syntax, so it is checked.
*
*------------------------------------------------------------
*/
DSEG
LefReadRect(FILE *f, int curlayer, float oscale)
{
char *token;
float llx, lly, urx, ury;
static struct dseg_ paintrect;
u_char needMatch = FALSE;
token = LefNextToken(f, TRUE);
if (*token == '(')
{
token = LefNextToken(f, TRUE);
needMatch = TRUE;
}
if (!token || sscanf(token, "%f", &llx) != 1) goto parse_error;
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &lly) != 1) goto parse_error;
token = LefNextToken(f, TRUE);
if (needMatch)
{
if (*token != ')') goto parse_error;
else token = LefNextToken(f, TRUE);
needMatch = FALSE;
}
if (*token == '(')
{
token = LefNextToken(f, TRUE);
needMatch = TRUE;
}
if (!token || sscanf(token, "%f", &urx) != 1) goto parse_error;
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &ury) != 1) goto parse_error;
if (needMatch)
{
token = LefNextToken(f, TRUE);
if (*token != ')') goto parse_error;
}
if (curlayer < 0) {
/* Issue warning but keep geometry with negative layer number */
LefError("No layer defined for RECT.\n");
}
/* Scale coordinates (microns to centimicrons) */
paintrect.x1 = llx / oscale;
paintrect.y1 = lly / oscale;
paintrect.x2 = urx / oscale;
paintrect.y2 = ury / oscale;
paintrect.layer = curlayer;
return (&paintrect);
parse_error:
LefError("Bad port geometry: RECT requires 4 values.\n");
return (DSEG)NULL;
}
/*
*------------------------------------------------------------
* Support routines for polygon reading
*------------------------------------------------------------
*/
#define HEDGE 0 /* Horizontal edge */
#define REDGE 1 /* Rising edge */
#define FEDGE -1 /* Falling edge */
/*
*------------------------------------------------------------
* lefLowX ---
*
* Sort routine to find the lowest X coordinate between
* two DPOINT structures passed from qsort()
*------------------------------------------------------------
*/
int
lefLowX(DPOINT *a, DPOINT *b)
{
DPOINT p = *a;
DPOINT q = *b;
if (p->x < q->x)
return (-1);
if (p->x > q->x)
return (1);
return (0);
}
/*
*------------------------------------------------------------
* lefLowY ---
*
* Sort routine to find the lowest Y coordinate between
* two DPOINT structures passed from qsort()
*------------------------------------------------------------
*/
int
lefLowY(DPOINT *a, DPOINT *b)
{
DPOINT p = *a;
DPOINT q = *b;
if (p->y < q->y)
return (-1);
if (p->y > q->y)
return (1);
return (0);
}
/*
*------------------------------------------------------------
* lefOrient ---
*
* Assign a direction to each of the edges in a polygon.
*
* Note that edges have been sorted, but retain the original
* linked list pointers, from which we can determine the
* path orientation
*
*------------------------------------------------------------
*/
char
lefOrient(DPOINT *edges, int nedges, int *dir)
{
int n;
DPOINT p, q;
for (n = 0; n < nedges; n++)
{
p = edges[n];
q = edges[n]->next;
if (p->y == q->y)
{
dir[n] = HEDGE;
continue;
}
if (p->x == q->x)
{
if (p->y < q->y)
{
dir[n] = REDGE;
continue;
}
if (p->y > q->y)
{
dir[n] = FEDGE;
continue;
}
/* Point connects to itself */
dir[n] = HEDGE;
continue;
}
/* It's not Manhattan, folks. */
return (FALSE);
}
return (TRUE);
}
/*
*------------------------------------------------------------
* lefCross ---
*
* See if an edge crosses a particular area.
* Return TRUE if edge if vertical and if it crosses the
* y-range defined by ybot and ytop. Otherwise return
* FALSE.
*------------------------------------------------------------
*/
char
lefCross(DPOINT edge, int dir, double ybot, double ytop)
{
double ebot, etop;
switch (dir)
{
case REDGE:
ebot = edge->y;
etop = edge->next->y;
return (ebot <= ybot && etop >= ytop);
case FEDGE:
ebot = edge->next->y;
etop = edge->y;
return (ebot <= ybot && etop >= ytop);
}
return (FALSE);
}
/*
*------------------------------------------------------------
* LefPolygonToRects --
*
* Convert Geometry information from a POLYGON statement
* into rectangles. NOTE: For now, this routine
* assumes that all points are Manhattan. It will flag
* non-Manhattan geometry
*
* the DSEG pointed to by rectListPtr is updated by
* having the list of rectangles appended to it.
*
*------------------------------------------------------------
*/
void
LefPolygonToRects(DSEG *rectListPtr, DPOINT pointlist)
{
DPOINT ptail, p, *pts, *edges;
DSEG rtail, rex, new;
int npts = 0;
int *dir;
int curr, wrapno, n;
double xbot, xtop, ybot, ytop;
if (pointlist == NULL) return;
/* Close the path by duplicating 1st point if necessary */
for (ptail = pointlist; ptail->next; ptail = ptail->next);
if ((ptail->x != pointlist->x) || (ptail->y != pointlist->y))
{
p = (DPOINT)malloc(sizeof(struct dpoint_));
p->x = pointlist->x;
p->y = pointlist->y;
p->layer = pointlist->layer;
p->next = NULL;
ptail->next = p;
}
// To do: Break out non-manhattan parts here.
// See CIFMakeManhattanPath in magic-8.0
rex = NULL;
for (p = pointlist; p->next; p = p->next, npts++);
pts = (DPOINT *)malloc(npts * sizeof(DPOINT));
edges = (DPOINT *)malloc(npts * sizeof(DPOINT));
dir = (int *)malloc(npts * sizeof(int));
npts = 0;
for (p = pointlist; p->next; p = p->next, npts++)
{
// pts and edges are two lists of pointlist entries
// that are NOT linked lists and can be shuffled
// around by qsort(). The linked list "next" pointers
// *must* be retained.
pts[npts] = p;
edges[npts] = p;
}
if (npts < 4)
{
LefError("Polygon with fewer than 4 points.\n");
goto done;
}
/* Sort points by low y, edges by low x */
qsort((char *)pts, npts, (int)sizeof(DPOINT), (__compar_fn_t)lefLowY);
qsort((char *)edges, npts, (int)sizeof(DPOINT), (__compar_fn_t)lefLowX);
/* Find out which direction each edge points */
if (!lefOrient(edges, npts, dir))
{
LefError("I can't handle non-manhattan polygons!\n");
goto done;
}
/* Scan the polygon from bottom to top. At each step, process
* a minimum-sized y-range of the polygon (i.e., a range such that
* there are no vertices inside the range). Use wrap numbers
* based on the edge orientations to determine how much of the
* x-range for this y-range should contain material.
*/
for (curr = 1; curr < npts; curr++)
{
/* Find the next minimum-sized y-range. */
ybot = pts[curr - 1]->y;
while (ybot == pts[curr]->y)
if (++curr >= npts) goto done;
ytop = pts[curr]->y;
/* Process all the edges that cross the y-range, from left
* to right.
*/
for (wrapno = 0, n = 0; n < npts; n++)
{
if (wrapno == 0) xbot = edges[n]->x;
if (!lefCross(edges[n], dir[n], ybot, ytop))
continue;
wrapno += (dir[n] == REDGE) ? 1 : -1;
if (wrapno == 0)
{
xtop = edges[n]->x;
if (xbot == xtop) continue;
new = (DSEG)malloc(sizeof(struct dseg_));
new->x1 = xbot;
new->x2 = xtop;
new->y1 = ybot;
new->y2 = ytop;
new->layer = edges[n]->layer;
new->next = rex;
rex = new;
}
}
}
done:
free(edges);
free(dir);
free(pts);
if (*rectListPtr == NULL)
*rectListPtr = rex;
else
{
for (rtail = *rectListPtr; rtail->next; rtail = rtail->next)
rtail->next = rex;
}
}
/*
*------------------------------------------------------------
* LefReadPolygon --
*
* Read Geometry information from a POLYGON statement
*
*------------------------------------------------------------
*/
DPOINT
LefReadPolygon(FILE *f, int curlayer, float oscale)
{
DPOINT plist = NULL, newPoint;
char *token;
double px, py;
while (1)
{
token = LefNextToken(f, TRUE);
if (token == NULL || *token == ';') break;
if (sscanf(token, "%lg", &px) != 1)
{
LefError("Bad X value in polygon.\n");
LefEndStatement(f);
break;
}
token = LefNextToken(f, TRUE);
if (token == NULL || *token == ';')
{
LefError("Missing Y value in polygon point!\n");
break;
}
if (sscanf(token, "%lg", &py) != 1)
{
LefError("Bad Y value in polygon.\n");
LefEndStatement(f);
break;
}
newPoint = (DPOINT)malloc(sizeof(struct dpoint_));
newPoint->x = px / (double)oscale;
newPoint->y = py / (double)oscale;
newPoint->layer = curlayer;
newPoint->next = plist;
plist = newPoint;
}
return plist;
}
/*
*------------------------------------------------------------
* LefReadGeometry --
*
* Read Geometry information from a LEF file.
* Used for PORT records and OBS statements.
*
* Results:
* Returns a linked list of all areas and types
* painted.
*
* Side Effects:
* Reads input from file f;
* Paints into the GATE lefMacro.
*
*------------------------------------------------------------
*/
enum lef_geometry_keys {LEF_LAYER = 0, LEF_WIDTH, LEF_PATH,
LEF_RECT, LEF_POLYGON, LEF_VIA, LEF_GEOMETRY_END};
DSEG
LefReadGeometry(GATE lefMacro, FILE *f, float oscale)
{
int curlayer = -1, otherlayer = -1;
char *token;
int keyword;
DSEG rectList = (DSEG)NULL;
DSEG paintrect, newRect;
DPOINT pointlist;
static char *geometry_keys[] = {
"LAYER",
"WIDTH",
"PATH",
"RECT",
"POLYGON",
"VIA",
"END",
NULL
};
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, geometry_keys);
if (keyword < 0)
{
LefError("Unknown keyword \"%s\" in LEF file; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case LEF_LAYER:
curlayer = LefReadLayers(f, FALSE, &otherlayer);
LefEndStatement(f);
break;
case LEF_WIDTH:
LefEndStatement(f);
break;
case LEF_PATH:
LefEndStatement(f);
break;
case LEF_RECT:
paintrect = (curlayer < 0) ? NULL : LefReadRect(f, curlayer, oscale);
if (paintrect)
{
/* Remember the area and layer */
newRect = (DSEG)malloc(sizeof(struct dseg_));
*newRect = *paintrect;
newRect->next = rectList;
rectList = newRect;
}
LefEndStatement(f);
break;
case LEF_POLYGON:
pointlist = LefReadPolygon(f, curlayer, oscale);
LefPolygonToRects(&rectList, pointlist);
break;
case LEF_VIA:
LefEndStatement(f);
break;
case LEF_GEOMETRY_END:
if (!LefParseEndStatement(f, NULL))
{
LefError("Geometry (PORT or OBS) END statement missing.\n");
keyword = -1;
}
break;
}
if (keyword == LEF_GEOMETRY_END) break;
}
return rectList;
}
/*
*------------------------------------------------------------
* LefReadPort --
*
* A wrapper for LefReadGeometry, which adds a label
* to the last rectangle generated by the geometry
* parsing.
*
* Results:
* None.
*
* Side Effects:
* Reads input from file f;
* Paints into the GATE lefMacro.
*
*------------------------------------------------------------
*/
void
LefReadPort(lefMacro, f, pinName, pinNum, pinDir, pinUse, oscale)
GATE lefMacro;
FILE *f;
char *pinName;
int pinNum, pinDir, pinUse;
float oscale;
{
DSEG rectList, rlist;
rectList = LefReadGeometry(lefMacro, f, oscale);
if (pinName != NULL) lefMacro->node[pinNum] = strdup(pinName);
if (pinNum >= 0) {
lefMacro->taps[pinNum] = rectList;
if (lefMacro->nodes <= pinNum)
lefMacro->nodes = (pinNum + 1);
}
else {
while (rectList) {
rlist = rectList->next;
free(rectList);
rectList = rlist;
}
}
}
/*
*------------------------------------------------------------
* LefReadPin --
*
* Read a PIN statement from a LEF file.
*
* Results:
* None.
*
* Side Effects:
* Reads input from file f;
* Paints into the GATE lefMacro.
*
*------------------------------------------------------------
*/
enum lef_pin_keys {LEF_DIRECTION = 0, LEF_USE, LEF_PORT, LEF_CAPACITANCE,
LEF_PIN_END};
void
LefReadPin(lefMacro, f, pinname, pinNum, oscale)
GATE lefMacro;
FILE *f;
char *pinname;
int pinNum;
float oscale;
{
char *token;
int keyword, subkey;
int pinDir = PORT_CLASS_DEFAULT;
int pinUse = PORT_USE_DEFAULT;
static char *pin_keys[] = {
"DIRECTION",
"USE",
"PORT",
"CAPACITANCE",
"END",
NULL
};
static char *pin_classes[] = {
"DEFAULT",
"INPUT",
"OUTPUT TRISTATE",
"OUTPUT",
"INOUT",
"FEEDTHRU",
NULL
};
static int lef_class_to_bitmask[] = {
PORT_CLASS_DEFAULT,
PORT_CLASS_INPUT,
PORT_CLASS_TRISTATE,
PORT_CLASS_OUTPUT,
PORT_CLASS_BIDIRECTIONAL,
PORT_CLASS_FEEDTHROUGH
};
static char *pin_uses[] = {
"DEFAULT",
"SIGNAL",
"ANALOG",
"POWER",
"GROUND",
"CLOCK",
NULL
};
static int lef_use_to_bitmask[] = {
PORT_USE_DEFAULT,
PORT_USE_SIGNAL,
PORT_USE_ANALOG,
PORT_USE_POWER,
PORT_USE_GROUND,
PORT_USE_CLOCK
};
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, pin_keys);
if (keyword < 0)
{
LefError("Unknown keyword \"%s\" in LEF file; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case LEF_DIRECTION:
token = LefNextToken(f, TRUE);
subkey = Lookup(token, pin_classes);
if (subkey < 0)
LefError("Improper DIRECTION statement\n");
else
pinDir = lef_class_to_bitmask[subkey];
LefEndStatement(f);
break;
case LEF_USE:
token = LefNextToken(f, TRUE);
subkey = Lookup(token, pin_uses);
if (subkey < 0)
LefError("Improper USE statement\n");
else
pinUse = lef_use_to_bitmask[subkey];
LefEndStatement(f);
break;
case LEF_PORT:
LefReadPort(lefMacro, f, pinname, pinNum, pinDir, pinUse, oscale);
break;
case LEF_CAPACITANCE:
LefEndStatement(f); /* Ignore. . . */
break;
case LEF_PIN_END:
if (!LefParseEndStatement(f, pinname))
{
LefError("Pin END statement missing.\n");
keyword = -1;
}
break;
}
if (keyword == LEF_PIN_END) break;
}
}
/*
*------------------------------------------------------------
* LefEndStatement --
*
* Read file input to EOF or a ';' token (end-of-statement)
* If we encounter a quote, make sure we don't terminate
* the statement on a semicolon that is part of the
* quoted material.
*
*------------------------------------------------------------
*/
void
LefEndStatement(FILE *f)
{
char *token;
while ((token = LefNextToken(f, TRUE)) != NULL)
if (*token == ';') break;
}
/*
*------------------------------------------------------------
*
* LefReadMacro --
*
* Read in a MACRO section from a LEF file.
*
* Results:
* None.
*
* Side Effects:
* Creates a new cell definition in the database.
*
*------------------------------------------------------------
*/
enum lef_macro_keys {LEF_CLASS = 0, LEF_SIZE, LEF_ORIGIN,
LEF_SYMMETRY, LEF_SOURCE, LEF_SITE, LEF_PIN, LEF_OBS,
LEF_TIMING, LEF_FOREIGN, LEF_MACRO_END};
void
LefReadMacro(f, mname, oscale)
FILE *f; /* LEF file being read */
char *mname; /* name of the macro */
float oscale; /* scale factor to um, usually 1 */
{
GATE lefMacro, altMacro;
char *token, tsave[128];
int keyword, pinNum;
float x, y;
u_char has_size, is_imported = FALSE;
struct dseg_ lefBBox;
static char *macro_keys[] = {
"CLASS",
"SIZE",
"ORIGIN",
"SYMMETRY",
"SOURCE",
"SITE",
"PIN",
"OBS",
"TIMING",
"FOREIGN",
"END",
NULL
};
/* Start by creating a new celldef */
lefMacro = (GATE)NULL;
for (altMacro = GateInfo; altMacro; altMacro = altMacro->next)
{
if (!strcmp(altMacro->gatename, mname)) {
lefMacro = altMacro;
break;
}
}
while (lefMacro)
{
int suffix;
char newname[256];
altMacro = lefMacro;
for (suffix = 1; altMacro != NULL; suffix++)
{
sprintf(newname, "%250s_%d", mname, suffix);
for (altMacro = GateInfo; altMacro; altMacro = altMacro->next)
if (!strcmp(altMacro->gatename, newname))
break;
}
LefError("Cell \"%s\" was already defined in this file. "
"Renaming original cell \"%s\"\n", mname, newname);
lefMacro->gatename = strdup(newname);
lefMacro = lefFindCell(mname);
}
// Create the new cell
lefMacro = (GATE)malloc(sizeof(struct gate_));
lefMacro->gatename = strdup(mname);
lefMacro->gatetype = NULL;
lefMacro->width = 0.0;
lefMacro->height = 0.0;
lefMacro->placedX = 0.0;
lefMacro->placedY = 0.0;
lefMacro->obs = (DSEG)NULL;
lefMacro->next = GateInfo;
lefMacro->nodes = 0;
GateInfo = lefMacro;
/* Initial values */
pinNum = 0;
has_size = FALSE;
lefBBox.x1 = 0.0;
lefBBox.y1 = 0.0;
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, macro_keys);
if (keyword < 0)
{
LefError("Unknown keyword \"%s\" in LEF file; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case LEF_CLASS:
token = LefNextToken(f, TRUE);
if (*token != '\n')
// DBPropPut(lefMacro, "LEFclass", token);
;
LefEndStatement(f);
break;
case LEF_SIZE:
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &x) != 1) goto size_error;
token = LefNextToken(f, TRUE); /* skip keyword "BY" */
if (!token) goto size_error;
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &y) != 1) goto size_error;
lefBBox.x2 = x + lefBBox.x1;
lefBBox.y2 = y + lefBBox.y1;
has_size = TRUE;
LefEndStatement(f);
break;
size_error:
LefError("Bad macro SIZE; requires values X BY Y.\n");
LefEndStatement(f);
break;
case LEF_ORIGIN:
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &x) != 1) goto origin_error;
token = LefNextToken(f, TRUE);
if (!token || sscanf(token, "%f", &y) != 1) goto origin_error;
lefBBox.x1 = -x;
lefBBox.y1 = -y;
if (has_size)
{
lefBBox.x2 += lefBBox.x1;
lefBBox.y2 += lefBBox.y1;
}
LefEndStatement(f);
break;
origin_error:
LefError("Bad macro ORIGIN; requires 2 values.\n");
LefEndStatement(f);
break;
case LEF_SYMMETRY:
token = LefNextToken(f, TRUE);
if (*token != '\n')
// DBPropPut(lefMacro, "LEFsymmetry", token + strlen(token) + 1);
;
LefEndStatement(f);
break;
case LEF_SOURCE:
token = LefNextToken(f, TRUE);
if (*token != '\n')
// DBPropPut(lefMacro, "LEFsource", token);
;
LefEndStatement(f);
break;
case LEF_SITE:
token = LefNextToken(f, TRUE);
if (*token != '\n')
// DBPropPut(lefMacro, "LEFsite", token);
;
LefEndStatement(f);
break;
case LEF_PIN:
token = LefNextToken(f, TRUE);
/* Diagnostic */
/*
Fprintf(stdout, " Macro defines pin %s\n", token);
*/
sprintf(tsave, "%.127s", token);
if (is_imported)
LefSkipSection(f, tsave);
else
LefReadPin(lefMacro, f, tsave, pinNum++, oscale);
break;
case LEF_OBS:
/* Diagnostic */
/*
Fprintf(stdout, " Macro defines obstruction\n");
*/
if (is_imported)
LefSkipSection(f, NULL);
else
lefMacro->obs = LefReadGeometry(lefMacro, f, oscale);
break;
case LEF_TIMING:
LefSkipSection(f, macro_keys[LEF_TIMING]);
break;
case LEF_FOREIGN:
LefEndStatement(f);
break;
case LEF_MACRO_END:
if (!LefParseEndStatement(f, mname))
{
LefError("Macro END statement missing.\n");
keyword = -1;
}
break;
}
if (keyword == LEF_MACRO_END) break;
}
/* Finish up creating the cell */
if (lefMacro) {
if (has_size) {
lefMacro->width = (lefBBox.x2 - lefBBox.x1);
lefMacro->height = (lefBBox.y2 - lefBBox.y1);
/* "placed" for macros (not instances) corresponds to the */
/* cell origin. */
lefMacro->placedX = lefBBox.x1;
lefMacro->placedY = lefBBox.y1;
}
else {
LefError("Gate %s has no size information!\n", lefMacro->gatename);
}
}
}
/*
*------------------------------------------------------------
*
* LefAddViaGeometry --
*
* Read in geometry for a VIA section from a LEF or DEF
* file.
*
* f LEF file being read
* lefl pointer to via info
* curlayer current tile type
* oscale output scaling
*
* Results:
* None.
*
* Side Effects:
* Adds to the lefLayer record for a via definition.
*
*------------------------------------------------------------
*/
void
LefAddViaGeometry(FILE *f, LefList lefl, int curlayer, float oscale)
{
DSEG currect;
DSEG viarect;
/* Rectangles for vias are read in units of 1/2 lambda */
currect = LefReadRect(f, curlayer, (oscale / 2));
if (currect == NULL) return;
/* First rect goes into info.via.area, others go into info.via.lr */
if (lefl->info.via.area.layer < 0)
{
lefl->info.via.area = *currect;
}
else
{
viarect = (DSEG)malloc(sizeof(struct dseg_));
*viarect = *currect;
viarect->next = lefl->info.via.lr;
lefl->info.via.lr = viarect;
}
}
/*
*------------------------------------------------------------
*
* LefReadLayerSection --
*
* Read in a LAYER, VIA, or VIARULE section from a LEF file.
*
* Results:
* None.
*
* Side Effects:
* Adds to the LEF layer info hash table.
*
*------------------------------------------------------------
*/
enum lef_layer_keys {LEF_LAYER_TYPE=0, LEF_LAYER_WIDTH,
LEF_LAYER_SPACING, LEF_LAYER_SPACINGTABLE,
LEF_LAYER_PITCH, LEF_LAYER_DIRECTION, LEF_LAYER_OFFSET,
LEF_VIA_DEFAULT, LEF_VIA_LAYER, LEF_VIA_RECT,
LEF_VIARULE_VIA, LEF_LAYER_END};
enum lef_spacing_keys {LEF_SPACING_RANGE=0, LEF_END_LAYER_SPACING};
void
LefReadLayerSection(f, lname, mode, lefl)
FILE *f; /* LEF file being read */
char *lname; /* name of the layer */
int mode; /* layer, via, or viarule */
LefList lefl; /* pointer to layer info */
{
char *token, *tp;
int keyword, typekey, entries, i;
struct seg_ viaArea;
int curlayer = -1;
double dvalue, oscale;
lefSpacingRule *newrule, *testrule;
/* These are defined in the order of CLASS_* in lefInt.h */
static char *layer_type_keys[] = {
"ROUTING",
"CUT",
"MASTERSLICE",
"OVERLAP",
NULL
};
static char *layer_keys[] = {
"TYPE",
"WIDTH",
"SPACING",
"SPACINGTABLE",
"PITCH",
"DIRECTION",
"OFFSET",
"DEFAULT",
"LAYER",
"RECT",
"VIA",
"END",
NULL
};
static char *spacing_keys[] = {
"RANGE",
";",
NULL
};
/* Database is assumed to be in microns. */
/* If not, we need to parse the UNITS record, which is */
/* currently ignored. */
oscale = 1;
viaArea.x1 = viaArea.x2 = 0;
viaArea.y1 = viaArea.y2 = 0;
viaArea.layer = -1;
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, layer_keys);
if (keyword < 0)
{
LefError("Unknown keyword \"%s\" in LEF file; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case LEF_LAYER_TYPE:
token = LefNextToken(f, TRUE);
if (*token != '\n')
{
typekey = Lookup(token, layer_type_keys);
if (typekey < 0)
LefError("Unknown layer type \"%s\" in LEF file; "
"ignoring.\n", token);
}
if (lefl->lefClass == CLASS_IGNORE) {
lefl->lefClass = typekey;
if (typekey == CLASS_ROUTE) {
lefl->info.route.width = 0.0;
lefl->info.route.spacing = NULL;
lefl->info.route.pitch = 0.0;
lefl->info.route.offset = 0.0;
lefl->info.route.hdirection = (u_char)0;
/* A routing type has been declared. Assume */
/* this takes the name "metal1", "M1", or some */
/* variant thereof. */
for (tp = lefl->lefName; *tp != '\0'; tp++) {
if (*tp >= '0' && *tp <= '9') {
sscanf(tp, "%d", &lefl->type);
/* "metal1", e.g., is assumed to be layer #0 */
/* This may not be a proper assumption, always */
lefl->type--;
break;
}
}
/* This is probably some special non-numerical */
/* name for a top metal layer. Take a stab at */
/* it, defining it to be the next layer up from */
/* whatever the previous topmost route layer */
/* was. This should work unless the LEF file */
/* is really weirdly written. */
if (lefl->type < 0) {
lefl->type = LefGetMaxLayer();
}
}
else if (typekey == CLASS_VIA) {
lefl->info.via.area.x1 = 0.0;
lefl->info.via.area.y1 = 0.0;
lefl->info.via.area.x2 = 0.0;
lefl->info.via.area.y2 = 0.0;
lefl->info.via.area.layer = -1;
lefl->info.via.cell = (GATE)NULL;
lefl->info.via.lr = (DSEG)NULL;
}
}
else if (lefl->lefClass != typekey) {
LefError("Attempt to reclassify layer %s from %s to %s\n",
lname, layer_type_keys[lefl->lefClass],
layer_type_keys[typekey]);
}
LefEndStatement(f);
break;
case LEF_LAYER_WIDTH:
token = LefNextToken(f, TRUE);
sscanf(token, "%lg", &dvalue);
lefl->info.route.width = dvalue / (double)oscale;
LefEndStatement(f);
break;
case LEF_LAYER_SPACING:
token = LefNextToken(f, TRUE);
sscanf(token, "%lg", &dvalue);
token = LefNextToken(f, TRUE);
typekey = Lookup(token, spacing_keys);
newrule = (lefSpacingRule *)malloc(sizeof(lefSpacingRule));
// If no range specified, then the rule goes in front
if (typekey != LEF_SPACING_RANGE) {
newrule->spacing = dvalue / (double)oscale;
newrule->width = 0.0;
newrule->next = lefl->info.route.spacing;
lefl->info.route.spacing = newrule;
}
else {
// Get range minimum, ignore range maximum, and sort
// the spacing order.
newrule->spacing = dvalue / (double)oscale;
token = LefNextToken(f, TRUE);
sscanf(token, "%lg", &dvalue);
newrule->width = dvalue / (double)oscale;
for (testrule = lefl->info.route.spacing; testrule;
testrule = testrule->next)
if (testrule->next == NULL || testrule->next->width >
newrule->width)
break;
if (!testrule) {
newrule->next = NULL;
lefl->info.route.spacing = newrule;
}
else {
newrule->next = testrule->next;
testrule->next = newrule;
}
token = LefNextToken(f, TRUE);
typekey = Lookup(token, spacing_keys);
}
if (typekey != LEF_END_LAYER_SPACING)
LefEndStatement(f);
break;
case LEF_LAYER_SPACINGTABLE:
// Use the values for the maximum parallel runlength
token = LefNextToken(f, TRUE); // "PARALLELRUNLENTTH"
entries = 0;
while (1) {
token = LefNextToken(f, TRUE);
if (*token == ';' || !strcmp(token, "WIDTH"))
break;
else
entries++;
}
if (*token != ';')
newrule = (lefSpacingRule *)malloc(sizeof(lefSpacingRule));
while (*token != ';') {
token = LefNextToken(f, TRUE); // Minimum width value
sscanf(token, "%lg", &dvalue);
newrule->width = dvalue / (double)oscale;
for (i = 0; i < entries; i++) {
token = LefNextToken(f, TRUE); // Spacing value
}
sscanf(token, "%lg", &dvalue);
newrule->spacing = dvalue / (double)oscale;
token = LefNextToken(f, TRUE);
for (testrule = lefl->info.route.spacing; testrule;
testrule = testrule->next)
if (testrule->next == NULL || testrule->next->width >
newrule->width)
break;
if (!testrule) {
newrule->next = NULL;
lefl->info.route.spacing = newrule;
}
else {
newrule->next = testrule->next;
testrule->next = newrule;
}
token = LefNextToken(f, TRUE);
if (strcmp(token, "WIDTH")) break;
}
break;
case LEF_LAYER_PITCH:
token = LefNextToken(f, TRUE);
sscanf(token, "%lg", &dvalue);
lefl->info.route.pitch = dvalue / (double)oscale;
LefEndStatement(f);
break;
case LEF_LAYER_DIRECTION:
token = LefNextToken(f, TRUE);
LefLower(token);
lefl->info.route.hdirection = (token[0] == 'h') ? TRUE : FALSE;
LefEndStatement(f);
break;
case LEF_LAYER_OFFSET:
token = LefNextToken(f, TRUE);
sscanf(token, "%lg", &dvalue);
lefl->info.route.offset = dvalue / (double)oscale;
LefEndStatement(f);
break;
case LEF_VIA_DEFAULT:
/* Do nothing; especially, don't look for end-of-statement! */
break;
case LEF_VIA_LAYER:
curlayer = LefReadLayer(f, FALSE);
LefEndStatement(f);
break;
case LEF_VIA_RECT:
LefAddViaGeometry(f, lefl, curlayer, oscale);
LefEndStatement(f);
break;
case LEF_VIARULE_VIA:
LefEndStatement(f);
break;
case LEF_LAYER_END:
if (!LefParseEndStatement(f, lname))
{
LefError("Layer END statement missing.\n");
keyword = -1;
}
break;
}
if (keyword == LEF_LAYER_END) break;
}
}
/*
*------------------------------------------------------------
*
* LefRead --
*
* Read a .lef file and generate all routing configuration
* structures and values from the LAYER, VIA, and MACRO sections
*
* Results:
* None.
*
* Side Effects:
* Many. Cell definitions are created and added to
* the GateInfo database.
*
*------------------------------------------------------------
*/
enum lef_sections {LEF_VERSION = 0, LEF_NAMESCASESENSITIVE,
LEF_PROPERTYDEFS, LEF_UNITS, LEF_SECTION_LAYER,
LEF_SECTION_VIA, LEF_SECTION_VIARULE,
LEF_SECTION_SPACING, LEF_SECTION_SITE, LEF_PROPERTY,
LEF_NOISETABLE, LEF_CORRECTIONTABLE, LEF_IRDROP,
LEF_ARRAY, LEF_SECTION_TIMING, LEF_EXTENSION, LEF_MACRO,
LEF_END};
void
LefRead(inName)
char *inName;
{
FILE *f;
char filename[256];
char *token;
char tsave[128];
int keyword, layer;
float oscale;
double xydiff;
LefList lefl;
DSEG grect;
GATE gateginfo;
static char *sections[] = {
"VERSION",
"NAMESCASESENSITIVE",
"PROPERTYDEFINITIONS",
"UNITS",
"LAYER",
"VIA",
"VIARULE",
"SPACING",
"SITE",
"PROPERTY",
"NOISETABLE",
"CORRECTIONTABLE",
"IRDROP",
"ARRAY",
"TIMING",
"BEGINEXT",
"MACRO",
"END",
NULL
};
if (!strrchr(inName, '.'))
sprintf(filename, "%s.lef", inName);
else
strcpy(filename, inName);
f = fopen(filename, "r");
if (f == NULL)
{
Fprintf(stderr, "Cannot open input file: ");
perror(filename);
return;
}
if (Verbose > 0) {
Fprintf(stdout, "Reading LEF data from file %s.\n", filename);
Flush(stdout);
}
oscale = 1;
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, sections);
if (keyword < 0)
{
LefError("Unknown keyword \"%s\" in LEF file; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case LEF_VERSION:
LefEndStatement(f);
break;
case LEF_NAMESCASESENSITIVE:
LefEndStatement(f);
break;
case LEF_PROPERTYDEFS:
LefSkipSection(f, sections[LEF_PROPERTYDEFS]);
break;
case LEF_UNITS:
LefSkipSection(f, sections[LEF_UNITS]);
break;
case LEF_SECTION_VIA:
case LEF_SECTION_VIARULE:
token = LefNextToken(f, TRUE);
sprintf(tsave, "%.127s", token);
lefl = LefFindLayer(token);
if (lefl == NULL)
{
lefl = (LefList)calloc(1, sizeof(lefLayer));
lefl->type = -1;
lefl->obsType = -1;
lefl->lefClass = CLASS_VIA;
lefl->info.via.area.x1 = 0.0;
lefl->info.via.area.y1 = 0.0;
lefl->info.via.area.x2 = 0.0;
lefl->info.via.area.y2 = 0.0;
lefl->info.via.area.layer = -1;
lefl->info.via.cell = (GATE)NULL;
lefl->info.via.lr = (DSEG)NULL;
lefl->lefName = strdup(token);
lefl->next = LefInfo;
LefInfo = lefl;
LefReadLayerSection(f, tsave, keyword, lefl);
}
else if (keyword == LEF_SECTION_VIARULE)
/* If we've already seen this via, don't reprocess. */
/* This deals with VIA followed by VIARULE. We */
/* really ought to have special processing for the */
/* VIARULE section. . . */
LefSkipSection(f, tsave);
else
{
LefError("Warning: Cut type \"%s\" redefined.\n", token);
lefl = LefRedefined(lefl, token);
LefReadLayerSection(f, tsave, keyword, lefl);
}
break;
case LEF_SECTION_LAYER:
token = LefNextToken(f, TRUE);
sprintf(tsave, "%.127s", token);
lefl = LefFindLayer(token);
if (lefl == (LefList)NULL)
{
lefl = (LefList)malloc(sizeof(lefLayer));
lefl->type = -1;
lefl->obsType = -1;
lefl->lefClass = CLASS_IGNORE; /* For starters */
lefl->lefName = strdup(token);
lefl->next = LefInfo;
LefInfo = lefl;
}
else
{
if (lefl && lefl->type < 0)
{
LefError("Layer %s is only defined for obstructions!\n", token);
LefSkipSection(f, tsave);
break;
}
}
LefReadLayerSection(f, tsave, keyword, lefl);
break;
case LEF_SECTION_SPACING:
LefSkipSection(f, sections[LEF_SECTION_SPACING]);
break;
case LEF_SECTION_SITE:
token = LefNextToken(f, TRUE);
if (Verbose > 0)
Fprintf(stdout, "LEF file: Defines site %s (ignored)\n", token);
sprintf(tsave, "%.127s", token);
LefSkipSection(f, tsave);
break;
case LEF_PROPERTY:
LefSkipSection(f, NULL);
break;
case LEF_NOISETABLE:
LefSkipSection(f, sections[LEF_NOISETABLE]);
break;
case LEF_CORRECTIONTABLE:
LefSkipSection(f, sections[LEF_CORRECTIONTABLE]);
break;
case LEF_IRDROP:
LefSkipSection(f, sections[LEF_IRDROP]);
break;
case LEF_ARRAY:
LefSkipSection(f, sections[LEF_ARRAY]);
break;
case LEF_SECTION_TIMING:
LefSkipSection(f, sections[LEF_SECTION_TIMING]);
break;
case LEF_EXTENSION:
LefSkipSection(f, sections[LEF_EXTENSION]);
break;
case LEF_MACRO:
token = LefNextToken(f, TRUE);
/* Diagnostic */
/*
Fprintf(stdout, "LEF file: Defines new cell %s\n", token);
*/
sprintf(tsave, "%.127s", token);
LefReadMacro(f, tsave, oscale);
break;
case LEF_END:
if (!LefParseEndStatement(f, "LIBRARY"))
{
LefError("END statement out of context.\n");
keyword = -1;
}
break;
}
if (keyword == LEF_END) break;
}
if (Verbose > 0) {
Fprintf(stdout, "LEF read: Processed %d lines.\n", lefCurrentLine);
LefError(NULL); /* print statement of errors, if any */
}
/* Cleanup */
if (f != NULL) fclose(f);
/* Make sure that the gate list has one entry called "pin" */
for (gateginfo = GateInfo; gateginfo; gateginfo = gateginfo->next)
if (!strcasecmp(gateginfo->gatename, "pin"))
break;
if (!gateginfo) {
/* Add a new GateInfo entry for pseudo-gate "pin" */
gateginfo = (GATE)malloc(sizeof(struct gate_));
gateginfo->gatetype = NULL;
gateginfo->gatename = (char *)malloc(4);
strcpy(gateginfo->gatename, "pin");
gateginfo->node[0] = strdup("pin");
gateginfo->width = 0.0;
gateginfo->height = 0.0;
gateginfo->placedX = 0.0;
gateginfo->placedY = 0.0;
gateginfo->nodes = 1;
grect = (DSEG)malloc(sizeof(struct dseg_));
grect->x1 = grect->x2 = 0.0;
grect->y1 = grect->y2 = 0.0;
grect->next = (DSEG)NULL;
gateginfo->taps[0] = grect;
gateginfo->obs = (DSEG)NULL;
gateginfo->next = GateInfo;
GateInfo = gateginfo;
}
PinMacro = gateginfo;
/* Work through all of the defined layers, and copy the names into */
/* the strings used for route output, overriding any information */
/* that may have been in the route.cfg file. */
/* Note that this runs through all the defined vias, from last to */
/* first defined. Check the X vs. Y dimension of the base layer. */
/* If X is longer, save as ViaX. If Y is longer, save as ViaY. */
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->lefClass == CLASS_ROUTE) {
strcpy(CIFLayer[lefl->type], lefl->lefName);
}
else if (lefl->lefClass == CLASS_VIA) {
if (lefl->info.via.lr) {
layer = MAX_LAYERS;
if (lefl->info.via.area.layer >= 0) {
layer = lefl->info.via.area.layer;
xydiff = (lefl->info.via.area.x2 - lefl->info.via.area.x1) -
(lefl->info.via.area.y2 - lefl->info.via.area.y1);
}
for (grect = lefl->info.via.lr; grect; grect = grect->next) {
if (grect->layer >= 0 && grect->layer < layer) {
layer = grect->layer;
xydiff = (grect->x2 - grect->x1) - (grect->y2 - grect->y1);
}
}
if (layer < MAX_LAYERS) {
if (xydiff > -EPS) {
free(ViaX[layer]);
ViaX[layer] = strdup(lefl->lefName);
}
else {
if (ViaY[layer] != NULL) free(ViaY[layer]);
ViaY[layer] = strdup(lefl->lefName);
}
}
}
}
}
}
|