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 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
|
/*--------------------------------------------------------------*/
/* tclqrouter.c: */
/* Tcl routines for qrouter command-line functions */
/* Copyright (c) 2013 Tim Edwards, Open Circuit Design, Inc. */
/*--------------------------------------------------------------*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <tk.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include "qrouter.h"
#include "maze.h"
#include "qconfig.h"
#include "lef.h"
#include "graphics.h"
#include "node.h"
#include "tkSimple.h"
/* Global variables */
Tcl_HashTable QrouterTagTable;
Tcl_Interp *qrouterinterp;
Tcl_Interp *consoleinterp;
int stepnet = -1;
int batchmode = 0;
/* Command structure */
typedef struct {
const char *cmdstr;
int (*func)(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
} cmdstruct;
/* Forward declarations of commands */
static int qrouter_map(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_start(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_stage1(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_stage2(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_stage3(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_writedef(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_writedelays(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_readdef(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_readlef(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_readconfig(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_failing(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_cost(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_tag(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_remove(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_obs(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_layerinfo(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_priority(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_ignore(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_via(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_resolution(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_congested(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_layers(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_passes(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_vdd(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_gnd(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_verbose(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_print(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static int qrouter_quit(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
static cmdstruct qrouter_commands[] =
{
{"tag", qrouter_tag},
{"start", qrouter_start},
{"stage1", qrouter_stage1},
{"stage2", qrouter_stage2},
{"stage3", qrouter_stage3},
{"write_def", qrouter_writedef},
{"read_def", qrouter_readdef},
{"read_lef", qrouter_readlef},
{"read_config", qrouter_readconfig},
{"write_delays", qrouter_writedelays},
{"layer_info", qrouter_layerinfo},
{"obstruction", qrouter_obs},
{"ignore", qrouter_ignore},
{"priority", qrouter_priority},
{"via", qrouter_via},
{"resolution", qrouter_resolution},
{"congested", qrouter_congested},
{"layers", qrouter_layers},
{"passes", qrouter_passes},
{"vdd", qrouter_vdd},
{"gnd", qrouter_gnd},
{"failing", qrouter_failing},
{"remove", qrouter_remove},
{"cost", qrouter_cost},
{"map", qrouter_map},
{"verbose", qrouter_verbose},
{"redraw", redraw},
{"print", qrouter_print},
{"quit", qrouter_quit},
{"", NULL} /* sentinel */
};
/*-----------------------*/
/* Tcl 8.4 compatibility */
/*-----------------------*/
#ifndef CONST84
#define CONST84
#endif
/*----------------------------------------------------------------------*/
/* Deal with systems which don't define va_copy(). */
/*----------------------------------------------------------------------*/
#ifndef HAVE_VA_COPY
#ifdef HAVE___VA_COPY
#define va_copy(a, b) __va_copy(a, b)
#else
#define va_copy(a, b) a = b
#endif
#endif
#ifdef ASG
extern int SetDebugLevel(int *level);
#endif
/*----------------------------------------------------------------------*/
/* Reimplement strdup() to use Tcl_Alloc(). */
/*----------------------------------------------------------------------*/
char *Tcl_Strdup(const char *s)
{
char *snew;
int slen;
slen = 1 + strlen(s);
snew = Tcl_Alloc(slen);
if (snew != NULL)
memcpy(snew, s, slen);
return snew;
}
/*----------------------------------------------------------------------*/
/* Reimplement vfprintf() as a call to Tcl_Eval(). */
/* */
/* Since the string goes through the interpreter, we need to escape */
/* various characters like brackets, braces, dollar signs, etc., that */
/* will otherwise be modified by the interpreter. */
/*----------------------------------------------------------------------*/
void tcl_vprintf(FILE *f, const char *fmt, va_list args_in)
{
va_list args;
static char outstr[128] = "puts -nonewline std";
char *outptr, *bigstr = NULL, *finalstr = NULL;
int i, nchars, escapes = 0;
/* If we are printing an error message, we want to bring attention */
/* to it by mapping the console window and raising it, as necessary. */
/* I'd rather do this internally than by Tcl_Eval(), but I can't */
/* find the right window ID to map! */
if ((f == stderr) && (consoleinterp != qrouterinterp)) {
Tk_Window tkwind;
tkwind = Tk_MainWindow(consoleinterp);
if ((tkwind != NULL) && (!Tk_IsMapped(tkwind)))
Tcl_Eval(consoleinterp, "wm deiconify .\n");
Tcl_Eval(consoleinterp, "raise .\n");
}
strcpy (outstr + 19, (f == stderr) ? "err \"" : "out \"");
outptr = outstr;
/* This mess circumvents problems with systems which do not have */
/* va_copy() defined. Some define __va_copy(); otherwise we must */
/* assume that args = args_in is valid. */
va_copy(args, args_in);
nchars = vsnprintf(outptr + 24, 102, fmt, args);
va_end(args);
if (nchars >= 102) {
va_copy(args, args_in);
bigstr = Tcl_Alloc(nchars + 26);
strncpy(bigstr, outptr, 24);
outptr = bigstr;
vsnprintf(outptr + 24, nchars + 2, fmt, args);
va_end(args);
}
else if (nchars == -1) nchars = 126;
for (i = 24; *(outptr + i) != '\0'; i++) {
if (*(outptr + i) == '\"' || *(outptr + i) == '[' ||
*(outptr + i) == ']' || *(outptr + i) == '\\' ||
*(outptr + i) == '$')
escapes++;
}
if (escapes > 0) {
finalstr = Tcl_Alloc(nchars + escapes + 26);
strncpy(finalstr, outptr, 24);
escapes = 0;
for (i = 24; *(outptr + i) != '\0'; i++) {
if (*(outptr + i) == '\"' || *(outptr + i) == '[' ||
*(outptr + i) == ']' || *(outptr + i) == '\\' ||
*(outptr + i) == '$') {
*(finalstr + i + escapes) = '\\';
escapes++;
}
*(finalstr + i + escapes) = *(outptr + i);
}
outptr = finalstr;
}
*(outptr + 24 + nchars + escapes) = '\"';
*(outptr + 25 + nchars + escapes) = '\0';
Tcl_Eval(consoleinterp, outptr);
if (bigstr != NULL) Tcl_Free(bigstr);
if (finalstr != NULL) Tcl_Free(finalstr);
}
/*------------------------------------------------------*/
/* Console output flushing which goes along with the */
/* routine tcl_vprintf() above. */
/*------------------------------------------------------*/
void tcl_stdflush(FILE *f)
{
Tcl_SavedResult state;
static char stdstr[] = "::flush stdxxx";
char *stdptr = stdstr + 11;
Tcl_SaveResult(qrouterinterp, &state);
strcpy(stdptr, (f == stderr) ? "err" : "out");
Tcl_Eval(qrouterinterp, stdstr);
Tcl_RestoreResult(qrouterinterp, &state);
}
/*----------------------------------------------------------------------*/
/* Reimplement fprintf() as a call to Tcl_Eval(). */
/*----------------------------------------------------------------------*/
void tcl_printf(FILE *f, const char *format, ...)
{
va_list ap;
va_start(ap, format);
tcl_vprintf(f, format, ap);
va_end(ap);
}
/*----------------------------------------------------------------------*/
/* Implement tag callbacks on functions */
/* Find any tags associated with a command and execute them. */
/*----------------------------------------------------------------------*/
int QrouterTagCallback(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
int objidx, result = TCL_OK;
char *postcmd, *substcmd, *newcmd, *sptr, *sres;
char *croot = Tcl_GetString(objv[0]);
Tcl_HashEntry *entry;
Tcl_SavedResult state;
int reset = FALSE;
int i, llen;
entry = Tcl_FindHashEntry(&QrouterTagTable, croot);
postcmd = (entry) ? (char *)Tcl_GetHashValue(entry) : NULL;
if (postcmd)
{
substcmd = (char *)Tcl_Alloc(strlen(postcmd) + 1);
strcpy(substcmd, postcmd);
sptr = substcmd;
/*--------------------------------------------------------------*/
/* Parse "postcmd" for Tk-substitution escapes */
/* Allowed escapes are: */
/* %W substitute the tk path of the calling window */
/* %r substitute the previous Tcl result string */
/* %R substitute the previous Tcl result string and */
/* reset the Tcl result. */
/* %[0-5] substitute the argument to the original command */
/* %N substitute all arguments as a list */
/* %% substitute a single percent character */
/* %* (all others) no action: print as-is. */
/*--------------------------------------------------------------*/
while ((sptr = strchr(sptr, '%')) != NULL)
{
switch (*(sptr + 1))
{
case 'W': {
char *tkpath = NULL;
Tk_Window tkwind = Tk_MainWindow(interp);
if (tkwind != NULL) tkpath = Tk_PathName(tkwind);
if (tkpath == NULL)
newcmd = (char *)Tcl_Alloc(strlen(substcmd));
else
newcmd = (char *)Tcl_Alloc(strlen(substcmd) + strlen(tkpath));
strcpy(newcmd, substcmd);
if (tkpath == NULL)
strcpy(newcmd + (int)(sptr - substcmd), sptr + 2);
else
{
strcpy(newcmd + (int)(sptr - substcmd), tkpath);
strcat(newcmd, sptr + 2);
}
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
} break;
case 'R':
reset = TRUE;
case 'r':
sres = (char *)Tcl_GetStringResult(interp);
newcmd = (char *)Tcl_Alloc(strlen(substcmd)
+ strlen(sres) + 1);
strcpy(newcmd, substcmd);
sprintf(newcmd + (int)(sptr - substcmd), "\"%s\"", sres);
strcat(newcmd, sptr + 2);
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
break;
case '0': case '1': case '2': case '3': case '4': case '5':
objidx = (int)(*(sptr + 1) - '0');
if ((objidx >= 0) && (objidx < objc))
{
newcmd = (char *)Tcl_Alloc(strlen(substcmd)
+ strlen(Tcl_GetString(objv[objidx])));
strcpy(newcmd, substcmd);
strcpy(newcmd + (int)(sptr - substcmd),
Tcl_GetString(objv[objidx]));
strcat(newcmd, sptr + 2);
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
}
else if (objidx >= objc)
{
newcmd = (char *)Tcl_Alloc(strlen(substcmd) + 1);
strcpy(newcmd, substcmd);
strcpy(newcmd + (int)(sptr - substcmd), sptr + 2);
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
}
else sptr++;
break;
case 'N':
llen = 1;
for (i = 1; i < objc; i++)
llen += (1 + strlen(Tcl_GetString(objv[i])));
newcmd = (char *)Tcl_Alloc(strlen(substcmd) + llen);
strcpy(newcmd, substcmd);
strcpy(newcmd + (int)(sptr - substcmd), "{");
for (i = 1; i < objc; i++) {
strcat(newcmd, Tcl_GetString(objv[i]));
if (i < (objc - 1))
strcat(newcmd, " ");
}
strcat(newcmd, "}");
strcat(newcmd, sptr + 2);
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
break;
case '%':
newcmd = (char *)Tcl_Alloc(strlen(substcmd) + 1);
strcpy(newcmd, substcmd);
strcpy(newcmd + (int)(sptr - substcmd), sptr + 1);
Tcl_Free(substcmd);
substcmd = newcmd;
sptr = substcmd;
break;
default:
break;
}
}
/* Fprintf(stderr, "Substituted tag callback is \"%s\"\n", substcmd); */
/* Flush(stderr); */
Tcl_SaveResult(interp, &state);
result = Tcl_Eval(interp, substcmd);
if ((result == TCL_OK) && (reset == FALSE))
Tcl_RestoreResult(interp, &state);
else
Tcl_DiscardResult(&state);
Tcl_Free(substcmd);
}
return result;
}
/*--------------------------------------------------------------*/
/* Add a command tag callback */
/*--------------------------------------------------------------*/
static int
qrouter_tag(ClientData clientData,
Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
Tcl_HashEntry *entry;
char *hstring;
int new;
if (objc != 2 && objc != 3)
return TCL_ERROR;
entry = Tcl_CreateHashEntry(&QrouterTagTable, Tcl_GetString(objv[1]), &new);
if (entry == NULL) return TCL_ERROR;
hstring = (char *)Tcl_GetHashValue(entry);
if (objc == 2)
{
Tcl_SetResult(interp, hstring, NULL);
return TCL_OK;
}
if (strlen(Tcl_GetString(objv[2])) == 0)
{
Tcl_DeleteHashEntry(entry);
}
else
{
hstring = Tcl_Strdup(Tcl_GetString(objv[2]));
Tcl_SetHashValue(entry, hstring);
}
return TCL_OK;
}
/*--------------------------------------------------------------*/
/* Initialization procedure for Tcl/Tk */
/*--------------------------------------------------------------*/
int
Qrouter_Init(Tcl_Interp *interp)
{
int cmdidx;
char command[256];
char version_string[20];
Tk_Window tktop;
char *nullgvar;
/* Interpreter sanity checks */
if (interp == NULL) return TCL_ERROR;
/* Remember the interpreter */
qrouterinterp = interp;
if (Tcl_InitStubs(interp, "8.5", 0) == NULL) return TCL_ERROR;
strcpy(command, "qrouter::");
/* NOTE: Qrouter makes calls to Tk routines that may or may not */
/* exist, depending on whether qrouter was called with or without */
/* graphics. We depend on the Tcl/Tk stubs methods to allow */
/* qrouter to run without linking to Tk libraries. */
nullgvar = (char *)Tcl_GetVar(interp, "no_graphics_mode", TCL_GLOBAL_ONLY);
if ((nullgvar == NULL) || !strcasecmp(nullgvar, "false")) {
if (Tk_InitStubs(interp, "8.5", 0) == NULL) return TCL_ERROR;
tktop = Tk_MainWindow(interp);
batchmode = 0;
}
else {
tktop = NULL;
batchmode = 1;
}
/* Create all of the commands (except "simple") */
for (cmdidx = 0; qrouter_commands[cmdidx].func != NULL; cmdidx++) {
sprintf(command + 9, "%s", qrouter_commands[cmdidx].cmdstr);
Tcl_CreateObjCommand(interp, command,
(Tcl_ObjCmdProc *)qrouter_commands[cmdidx].func,
(ClientData)tktop, (Tcl_CmdDeleteProc *) NULL);
}
if (tktop != NULL) {
Tcl_CreateObjCommand(interp, "simple",
(Tcl_ObjCmdProc *)Tk_SimpleObjCmd,
(ClientData)tktop, (Tcl_CmdDeleteProc *) NULL);
}
Tcl_Eval(interp, "lappend auto_path .");
sprintf(version_string, "%s", VERSION);
Tcl_SetVar(interp, "QROUTER_VERSION", version_string, TCL_GLOBAL_ONLY);
Tcl_Eval(interp, "namespace eval qrouter namespace export *");
Tcl_PkgProvide(interp, "Qrouter", version_string);
/* Initialize the console interpreter, if there is one. */
if ((consoleinterp = Tcl_GetMaster(interp)) == NULL)
consoleinterp = interp;
/* Initialize the command tag table */
Tcl_InitHashTable(&QrouterTagTable, TCL_STRING_KEYS);
return TCL_OK;
}
/*------------------------------------------------------*/
/* Command "start" */
/*------------------------------------------------------*/
static int
qrouter_start(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int i, result, argc;
char *scriptfile = NULL;
char **argv;
/* For compatibility with the original C code, convert Tcl */
/* object arguments to strings. Handle "-s <name>", */
/* which is not handled by runqrouter(), and source the */
/* script <name> between runqrouter() and read_def(). */
argv = (char **)malloc((objc - 1) * sizeof(char *));
argc = 0;
for (i = 1; i < objc; i++) {
if (!strcmp(Tcl_GetString(objv[i]), "-s"))
scriptfile = strdup(Tcl_GetString(objv[i + 1]));
argv[argc++] = strdup(Tcl_GetString(objv[i]));
}
result = runqrouter(argc, argv);
if ((result == 0) && (batchmode == 0)) GUI_init(interp);
for (i = 0; i < argc; i++)
free(argv[i]);
free(argv);
if (scriptfile != NULL) {
/* First check that the script file exists. If not, */
/* then generate an error here. */
FILE *scriptf = fopen(scriptfile, "r");
if (scriptf == NULL) {
Fprintf(stderr, "Script file \"%s\" unavaliable or unreadable.\n",
scriptfile);
Tcl_SetResult(interp, "Script file unavailable or unreadable.", NULL);
result = TCL_ERROR;
}
else {
fclose(scriptf);
result = Tcl_EvalFile(interp, scriptfile);
}
free(scriptfile);
/* The script file should determine whether or not to */
/* exit by including the "quit" command. But if there */
/* is an error in the script, then always quit. */
if (result != TCL_OK) {
/* Make sure Tcl has generated all output */
while (Tcl_DoOneEvent(TCL_DONT_WAIT) != 0);
/* And exit gracefully */
qrouter_quit(clientData, interp, 1, objv);
}
}
if ((DEFfilename != NULL) && (Nlgates == NULL)) {
read_def(NULL);
draw_layout();
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command: qrouter_quit */
/* */
/* Call tkcon's exit routine, which will make sure */
/* the history file is updated before final exit. */
/*------------------------------------------------------*/
int
qrouter_quit(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
if (objc != 1) {
Tcl_WrongNumArgs(interp, 1, objv, "(no arguments)");
return TCL_ERROR;
}
if (consoleinterp == interp)
Tcl_Exit(TCL_OK);
else
Tcl_Eval(interp, "catch {tkcon eval exit}\n");
return TCL_OK; /* Not reached */
}
/*------------------------------------------------------*/
/* Command "map" */
/* */
/* Specify what to draw in the graphics window */
/* */
/* map obstructions draw routes (normal) */
/* map congestion draw actual congestion */
/* map estimate draw estimated congestion */
/* map none route background is plain */
/* map routes draw routes over map */
/* map noroutes don't draw routes over map */
/* map unrouted draw unrouted nets over map */
/* map nounrouted don't draw unrouted nets */
/*------------------------------------------------------*/
static int
qrouter_map(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int idx, result;
static char *subCmds[] = {
"obstructions", "congestion", "estimate", "none",
"routes", "noroutes", "unrouted", "nounrouted", NULL
};
enum SubIdx {
ObsIdx, CongIdx, EstIdx, NoneIdx, RouteIdx, NoRouteIdx, UnroutedIdx, NoUnroutedIdx
};
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
else if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx)) != TCL_OK)
return result;
switch (idx) {
case ObsIdx:
if ((mapType & MAP_MASK) != MAP_OBSTRUCT) {
mapType &= ~MAP_MASK;
mapType |= MAP_OBSTRUCT;
draw_layout();
}
break;
case CongIdx:
if ((mapType & MAP_MASK) != MAP_CONGEST) {
mapType &= ~MAP_MASK;
mapType |= MAP_CONGEST;
draw_layout();
}
break;
case EstIdx:
if ((mapType & MAP_MASK) != MAP_ESTIMATE) {
mapType &= ~MAP_MASK;
mapType |= MAP_ESTIMATE;
draw_layout();
}
break;
case NoneIdx:
if ((mapType & MAP_MASK) != MAP_NONE) {
mapType &= ~MAP_MASK;
mapType |= MAP_NONE;
draw_layout();
}
break;
case RouteIdx:
mapType |= DRAW_ROUTES;
draw_layout();
break;
case NoRouteIdx:
mapType &= ~DRAW_ROUTES;
draw_layout();
break;
case UnroutedIdx:
mapType |= DRAW_UNROUTED;
draw_layout();
break;
case NoUnroutedIdx:
mapType &= ~DRAW_UNROUTED;
draw_layout();
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Find the net named "netname" in the list of nets */
/* and return a pointer to it. */
/* */
/* NOTE: Really need a hash table lookup here! */
/*------------------------------------------------------*/
NET LookupNet(char *netname)
{
NET net;
int i;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (!strcmp(net->netname, netname))
return net;
}
return NULL;
}
/*------------------------------------------------------*/
/* Find the net with number "number" in the list of */
/* nets and return a pointer to it. */
/*------------------------------------------------------*/
NET LookupNetNr(int number)
{
NET net;
int i;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (net->netnum == number)
return net;
}
return NULL;
}
/*------------------------------------------------------*/
/* Find the gate instance named gatename and return a */
/* pointer to it. */
/*------------------------------------------------------*/
GATE LookupGate(char *gatename)
{
GATE gate;
for (gate = Nlgates; gate != NULL; gate = gate->next) {
if (!strcmp(gate->gatename, gatename))
return gate;
}
return NULL;
}
/*------------------------------------------------------*/
/* Command "stage1" */
/* */
/* Execute stage1 routing. This works through the */
/* entire netlist, routing as much as possible but not */
/* doing any rip-up and re-route. Nets that fail to */
/* route are put in the "FailedNets" list. */
/* */
/* The interpreter result is set to the number of */
/* failed routes at the end of the first stage. */
/* */
/* Options: */
/* */
/* stage1 debug Draw the area being searched in */
/* real-time. This slows down the */
/* algorithm and is intended only */
/* for diagnostic use. */
/* stage1 step Single-step stage one. */
/* stage1 mask none Don't limit the search area */
/* stage1 mask auto Select the mask automatically */
/* stage1 mask bbox Use the net bbox as a mask */
/* stage1 mask <value> Set the mask size to <value>, */
/* an integer typ. 0 and up. */
/* stage1 route <net> Route net named <net> only. */
/* */
/* stage1 force Force a terminal to be routable */
/*------------------------------------------------------*/
static int
qrouter_stage1(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
u_char dodebug;
u_char dostep;
u_char saveForce, saveOverhead;
int i, idx, idx2, val, result, failcount = 0;
NET net = NULL;
static char *subCmds[] = {
"debug", "mask", "route", "force", "step", NULL
};
enum SubIdx {
DebugIdx, MaskIdx, RouteIdx, ForceIdx, StepIdx
};
static char *maskSubCmds[] = {
"none", "auto", "bbox", NULL
};
enum maskSubIdx {
NoneIdx, AutoIdx, BboxIdx
};
// Command defaults
dodebug = FALSE;
dostep = FALSE;
maskMode = MASK_AUTO; // Mask mode is auto unless specified
// Save these global defaults in case they are locally changed
saveForce = forceRoutable;
if (objc >= 2) {
for (i = 1; i < objc; i++) {
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK)
return result;
switch (idx) {
case DebugIdx:
dodebug = TRUE;
break;
case StepIdx:
dostep = TRUE;
break;
case ForceIdx:
forceRoutable = TRUE;
break;
case RouteIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "route ?net?");
return TCL_ERROR;
}
i++;
net = LookupNet(Tcl_GetString(objv[i]));
if (net == NULL) {
Tcl_SetResult(interp, "No such net", NULL);
return TCL_ERROR;
}
break;
case MaskIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "mask ?type?");
return TCL_ERROR;
}
i++;
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)maskSubCmds, "type", 0,
&idx2)) != TCL_OK) {
Tcl_ResetResult(interp);
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
else if (val < 0 || val > 200) {
Tcl_SetResult(interp, "Bad mask value", NULL);
return TCL_ERROR;
}
maskMode = (u_char)val;
}
else {
switch(idx2) {
case NoneIdx:
maskMode = MASK_NONE;
break;
case AutoIdx:
maskMode = MASK_AUTO;
break;
case BboxIdx:
maskMode = MASK_BBOX;
break;
}
}
break;
}
}
}
if (dostep == FALSE) stepnet = -1;
else stepnet++;
if (net == NULL)
failcount = dofirststage(dodebug, stepnet);
else {
if ((net != NULL) && (net->netnodes != NULL)) {
result = doroute(net, (u_char)0, dodebug);
failcount = (result == 0) ? 0 : 1;
/* Remove from FailedNets list if routing */
/* was successful */
if (result == 0 && FailedNets != NULL) {
NETLIST fnet, lnet = NULL;
for (fnet = FailedNets; fnet != NULL; fnet = fnet->next) {
if (fnet->net == net) {
if (lnet == NULL)
FailedNets = fnet->next;
else
lnet->next = fnet->next;
free(fnet);
break;
}
lnet = fnet;
}
}
}
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(failcount));
if (stepnet >= (Numnets - 1)) stepnet = -1;
// Restore global defaults in case they were locally changed
forceRoutable = saveForce;
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "stage2" */
/* */
/* Execute stage2 routing. This stage works through */
/* the "FailedNets" list, routing with collisions, and */
/* then ripping up the colliding nets and appending */
/* them to the "FailedNets" list. */
/* */
/* The interpreter result is set to the number of */
/* failed routes at the end of the second stage. */
/* */
/* Options: */
/* */
/* stage2 debug Draw the area being searched in */
/* real-time. This slows down the */
/* algorithm and is intended only */
/* for diagnostic use. */
/* stage2 step Single-step stage two */
/* stage2 mask none Don't limit the search area */
/* stage2 mask auto Select the mask automatically */
/* stage2 mask bbox Use the net bbox as a mask */
/* stage2 mask <value> Set the mask size to <value>, */
/* an integer typ. 0 and up. */
/* stage2 limit <n> Fail route if solution collides */
/* with more than <n> nets. */
/* stage2 route <net> Route net named <net> only. */
/* */
/* stage2 force Force a terminal to be routable */
/* stage2 break Only rip up colliding segment */
/* stage2 effort <n> Level of effort (default 100) */
/*------------------------------------------------------*/
static int
qrouter_stage2(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
u_int effort;
u_char dodebug;
u_char dostep;
u_char onlybreak;
u_char saveForce, saveOverhead;
int i, idx, idx2, val, result, failcount;
NET net = NULL;
static char *subCmds[] = {
"debug", "mask", "limit", "route", "force", "tries", "step",
"break", "effort", NULL
};
enum SubIdx {
DebugIdx, MaskIdx, LimitIdx, RouteIdx, ForceIdx, TriesIdx, StepIdx,
BreakIdx, EffortIdx
};
static char *maskSubCmds[] = {
"none", "auto", "bbox", NULL
};
enum maskSubIdx {
NoneIdx, AutoIdx, BboxIdx
};
// Command defaults
dodebug = FALSE;
dostep = FALSE;
onlybreak = FALSE;
maskMode = MASK_AUTO; // Mask mode is auto unless specified
// Save these global defaults in case they are locally changed
saveForce = forceRoutable;
ripLimit = 10; // Rip limit is 10 unless specified
effort = 100; // Moderate to high effort
if (objc >= 2) {
for (i = 1; i < objc; i++) {
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK)
return result;
switch (idx) {
case DebugIdx:
dodebug = TRUE;
break;
case StepIdx:
dostep = TRUE;
break;
case BreakIdx:
onlybreak = TRUE;
break;
case ForceIdx:
forceRoutable = TRUE;
break;
case EffortIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "effort ?num?");
return TCL_ERROR;
}
i++;
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
effort = (u_int)val;
break;
case TriesIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "tries ?num?");
return TCL_ERROR;
}
i++;
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
Tcl_SetResult(interp, "\"tries\" deprecated, "
"use \"effort\" instead.", NULL);
effort = (u_char)val * 100;
break;
case RouteIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "route ?net?");
return TCL_ERROR;
}
i++;
net = LookupNet(Tcl_GetString(objv[i]));
if (net == NULL) {
Tcl_SetResult(interp, "No such net", NULL);
return TCL_ERROR;
}
break;
case LimitIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "limit ?num?");
return TCL_ERROR;
}
i++;
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
ripLimit = (u_char)val;
break;
case MaskIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "mask ?type?");
return TCL_ERROR;
}
i++;
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)maskSubCmds, "type", 0,
&idx2)) != TCL_OK) {
Tcl_ResetResult(interp);
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
else if (val < 0 || val > 200) {
Tcl_SetResult(interp, "Bad mask value", NULL);
return TCL_ERROR;
}
maskMode = (u_char)val;
}
else {
switch(idx2) {
case NoneIdx:
maskMode = MASK_NONE;
break;
case AutoIdx:
maskMode = MASK_AUTO;
break;
case BboxIdx:
maskMode = MASK_BBOX;
break;
}
}
break;
}
}
}
if (net == NULL)
failcount = dosecondstage(dodebug, dostep, onlybreak, effort);
else
failcount = route_net_ripup(net, dodebug, onlybreak);
Tcl_SetObjResult(interp, Tcl_NewIntObj(failcount));
draw_layout();
// Restore global defaults in case they were locally changed
forceRoutable = saveForce;
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "stage3" */
/* */
/* Execute stage3 routing. This works through the */
/* entire netlist, ripping up each route in turn and */
/* re-routing it. */
/* */
/* The interpreter result is set to the number of */
/* failed routes at the end of the first stage. */
/* */
/* Options: */
/* */
/* stage3 debug Draw the area being searched in */
/* real-time. This slows down the */
/* algorithm and is intended only */
/* for diagnostic use. */
/* stage3 step Single-step stage three. */
/* stage3 mask none Don't limit the search area */
/* stage3 mask auto Select the mask automatically */
/* stage3 mask bbox Use the net bbox as a mask */
/* stage3 mask <value> Set the mask size to <value>, */
/* an integer typ. 0 and up. */
/* stage3 route <net> Route net named <net> only. */
/* */
/* stage3 force Force a terminal to be routable */
/* stage3 effort Level of effort (default 100) */
/*------------------------------------------------------*/
static int
qrouter_stage3(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
u_int effort;
u_char dodebug;
u_char dostep;
u_char saveForce, saveOverhead;
int i, idx, idx2, val, result, failcount = 0;
NET net = NULL;
static char *subCmds[] = {
"debug", "mask", "route", "force", "step", "effort", NULL
};
enum SubIdx {
DebugIdx, MaskIdx, RouteIdx, ForceIdx, StepIdx, EffortIdx
};
static char *maskSubCmds[] = {
"none", "auto", "bbox", NULL
};
enum maskSubIdx {
NoneIdx, AutoIdx, BboxIdx
};
// Command defaults
dodebug = FALSE;
dostep = FALSE;
maskMode = MASK_AUTO; // Mask mode is auto unless specified
effort = 100; // Moderate to high effort
// Save these global defaults in case they are locally changed
saveForce = forceRoutable;
if (objc >= 2) {
for (i = 1; i < objc; i++) {
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK)
return result;
switch (idx) {
case DebugIdx:
dodebug = TRUE;
break;
case StepIdx:
dostep = TRUE;
break;
case ForceIdx:
forceRoutable = TRUE;
break;
case EffortIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "effort ?num?");
return TCL_ERROR;
}
i++;
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
effort = (u_int)val;
break;
case RouteIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "route ?net?");
return TCL_ERROR;
}
i++;
net = LookupNet(Tcl_GetString(objv[i]));
if (net == NULL) {
Tcl_SetResult(interp, "No such net", NULL);
return TCL_ERROR;
}
break;
case MaskIdx:
if (i >= objc - 1) {
Tcl_WrongNumArgs(interp, 0, objv, "mask ?type?");
return TCL_ERROR;
}
i++;
if ((result = Tcl_GetIndexFromObj(interp, objv[i],
(CONST84 char **)maskSubCmds, "type", 0,
&idx2)) != TCL_OK) {
Tcl_ResetResult(interp);
result = Tcl_GetIntFromObj(interp, objv[i], &val);
if (result != TCL_OK) return result;
else if (val < 0 || val > 200) {
Tcl_SetResult(interp, "Bad mask value", NULL);
return TCL_ERROR;
}
maskMode = (u_char)val;
}
else {
switch(idx2) {
case NoneIdx:
maskMode = MASK_NONE;
break;
case AutoIdx:
maskMode = MASK_AUTO;
break;
case BboxIdx:
maskMode = MASK_BBOX;
break;
}
}
break;
}
}
}
if (dostep == FALSE) stepnet = -1;
else stepnet++;
if (net == NULL)
failcount = dothirdstage(dodebug, stepnet, effort);
else {
/* To do: Duplicate behavior of dothirdstage(), which */
/* is to retain the original route solution and restore */
/* it in case the routing fails. */
if ((net != NULL) && (net->netnodes != NULL)) {
result = doroute(net, (u_char)0, dodebug);
failcount = (result == 0) ? 0 : 1;
/* Remove from FailedNets list if routing */
/* was successful */
if (result == 0 && FailedNets != NULL) {
NETLIST fnet, lnet = NULL;
for (fnet = FailedNets; fnet != NULL; fnet = fnet->next) {
if (fnet->net == net) {
if (lnet == NULL)
FailedNets = fnet->next;
else
lnet->next = fnet->next;
free(fnet);
break;
}
lnet = fnet;
}
}
}
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(failcount));
if (stepnet >= (Numnets - 1)) stepnet = -1;
// Restore global defaults in case they were locally changed
forceRoutable = saveForce;
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "remove" */
/* */
/* Remove a net or nets, or all nets, from the */
/* design. */
/* */
/* Options: */
/* */
/* remove all Remove all nets from the design */
/* remove net <name> [...] */
/* Remove the named net(s) from */
/* the design. */
/*------------------------------------------------------*/
static int
qrouter_remove(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int result, idx, i;
NET net;
static char *subCmds[] = {
"all", "net", NULL
};
enum SubIdx {
AllIdx, NetIdx
};
if (objc < 2) {
Tcl_WrongNumArgs(interp, 0, objv, "?option?");
return TCL_ERROR;
}
else {
if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK)
return result;
switch (idx) {
case AllIdx:
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
ripup_net(net, (u_char)1, (u_char)1, (u_char)0);
}
draw_layout();
break;
case NetIdx:
for (i = 2; i < objc; i++) {
net = LookupNet(Tcl_GetString(objv[i]));
if (net != NULL)
ripup_net(net, (u_char)1, (u_char)1, (u_char)0);
}
draw_layout();
break;
}
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "failing" */
/* */
/* List the nets that have failed routing. */
/* */
/* Options: */
/* */
/* failing all Move all nets to FailedNets */
/* ordered by the standard metric */
/* failing unordered Move all nets to FailedNets, */
/* as originally ordered */
/* failing summary List of failed and total nets */
/*------------------------------------------------------*/
static int
qrouter_failing(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *lobj;
NETLIST nl, nlast;
NET net;
int i, failcount;
if (objc == 2) {
if (!strncmp(Tcl_GetString(objv[1]), "unorder", 7)) {
// Free up FailedNets list and then move all
// nets to FailedNets
while (FailedNets != NULL) {
nl = FailedNets->next;
FailedNets = FailedNets->next;
free(nl);
}
nlast = NULL;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
nl = (NETLIST)malloc(sizeof(struct netlist_));
nl->net = net;
nl->next = NULL;
if (nlast == NULL)
FailedNets = nl;
else
nlast->next = nl;
nlast = nl;
}
}
else if (!strncmp(Tcl_GetString(objv[1]), "all", 3)) {
while (FailedNets != NULL) {
nl = FailedNets->next;
FailedNets = FailedNets->next;
free(nl);
}
create_netorder(0);
nlast = NULL;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
nl = (NETLIST)malloc(sizeof(struct netlist_));
nl->net = net;
nl->next = NULL;
if (nlast == NULL)
FailedNets = nl;
else
nlast->next = nl;
nlast = nl;
}
}
else if (!strncmp(Tcl_GetString(objv[1]), "summary", 7)) {
failcount = countlist(FailedNets);
lobj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(interp, lobj, Tcl_NewIntObj(failcount));
Tcl_ListObjAppendElement(interp, lobj, Tcl_NewIntObj(Numnets));
Tcl_SetObjResult(interp, lobj);
}
else {
Tcl_WrongNumArgs(interp, 0, objv, "all or unordered");
return TCL_ERROR;
}
}
else {
lobj = Tcl_NewListObj(0, NULL);
for (nl = FailedNets; nl; nl = nl->next) {
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(nl->net->netname, -1));
}
Tcl_SetObjResult(interp, lobj);
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "read_lef" */
/*------------------------------------------------------*/
static int
qrouter_readlef(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
char *LEFfile;
int mscale;
int i;
if (objc != 2) {
Tcl_SetResult(interp, "No LEF filename specified!", NULL);
return TCL_ERROR;
}
LEFfile = Tcl_GetString(objv[1]);
mscale = LefRead(LEFfile);
if (Scales.mscale < mscale) Scales.mscale = mscale;
for (i = 0; i < Num_layers; i++) {
/* Set Vert and PitchX from route info */
Vert[i] = (1 - LefGetRouteOrientation(i));
PitchX[i] = LefGetRoutePitch(i);
}
post_config();
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "read_def" */
/*------------------------------------------------------*/
static int
qrouter_readdef(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
if ((DEFfilename == NULL) && (objc != 2)) {
Tcl_SetResult(interp, "No DEF filename specified!", NULL);
return TCL_ERROR;
}
if (objc == 2)
read_def(Tcl_GetString(objv[1]));
else
read_def(NULL);
// Redisplay
draw_layout();
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "write_def" */
/*------------------------------------------------------*/
static int
qrouter_writedef(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
char *DEFoutfile = NULL;
if (objc == 2)
DEFoutfile = Tcl_GetString(objv[1]);
else if (DEFfilename == NULL) {
Tcl_SetResult(interp, "No DEF filename specified!", NULL);
return TCL_ERROR;
}
write_def(DEFoutfile);
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "write_delays" */
/*------------------------------------------------------*/
static int
qrouter_writedelays(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
char *delayoutfile = NULL;
if (objc == 2)
delayoutfile = Tcl_GetString(objv[1]);
else if (delayfilename == NULL) {
Tcl_SetResult(interp, "No delay filename specified!", NULL);
return TCL_ERROR;
}
write_delays(delayoutfile);
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "read_config" */
/*------------------------------------------------------*/
static int
qrouter_readconfig(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
FILE *configFILE;
char *configname = NULL;
if (objc == 2)
configname = Tcl_GetString(objv[1]);
else {
Tcl_SetResult(interp, "No configuration filename specified!",
NULL);
return TCL_ERROR;
}
configFILE = fopen(configname, "r");
if (configFILE == NULL) {
Tcl_SetResult(interp, "Failed to open configuration file.",
NULL);
return TCL_ERROR;
}
read_config(configFILE, FALSE);
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "obstruction" */
/* */
/* Create an obstruction manually by specifying a */
/* rectangular bounding box and layer of the obstructed */
/* area. Without options, returns a list of the */
/* defined user obstruction areas. */
/* */
/* Options: */
/* */
/* obstruction */
/* obstruction <xmin> <ymin> <xmax> <ymax> <layer> */
/*------------------------------------------------------*/
static int
qrouter_obs(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *lobj;
Tcl_Obj *oobj;
LefList lefl;
char *layername;
DSEG obs;
int layer, result;
double x1, x2, y1, y2;
if (objc == 1) {
lobj = Tcl_NewListObj(0, NULL);
for (obs = UserObs; obs; obs = obs->next) {
lefl = LefFindLayerByNum(obs->layer);
if (lefl == NULL) continue;
oobj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(interp, oobj, Tcl_NewDoubleObj(obs->x1));
Tcl_ListObjAppendElement(interp, oobj, Tcl_NewDoubleObj(obs->x2));
Tcl_ListObjAppendElement(interp, oobj, Tcl_NewDoubleObj(obs->y1));
Tcl_ListObjAppendElement(interp, oobj, Tcl_NewDoubleObj(obs->y2));
Tcl_ListObjAppendElement(interp, oobj,
Tcl_NewStringObj(lefl->lefName, -1));
Tcl_ListObjAppendElement(interp, lobj, oobj);
}
Tcl_SetObjResult(interp, lobj);
}
else if (objc != 6) {
Tcl_WrongNumArgs(interp, 1, objv, "x1 x2 y1 y2 layer");
return TCL_ERROR;
}
else {
layername = Tcl_GetString(objv[5]);
layer = LefFindLayerNum(layername);
if (layer < 0) {
Tcl_SetResult(interp, "No such layer name", NULL);
return TCL_ERROR;
}
else {
result = Tcl_GetDoubleFromObj(interp, objv[1], &x1);
if (result != TCL_OK) return result;
result = Tcl_GetDoubleFromObj(interp, objv[2], &y1);
if (result != TCL_OK) return result;
result = Tcl_GetDoubleFromObj(interp, objv[3], &x2);
if (result != TCL_OK) return result;
result = Tcl_GetDoubleFromObj(interp, objv[4], &y2);
if (result != TCL_OK) return result;
obs = (DSEG)malloc(sizeof(struct dseg_));
obs->x1 = x1;
obs->x2 = x2;
obs->y1 = y1;
obs->y2 = y2;
obs->layer = layer;
obs->next = UserObs;
UserObs = obs;
}
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "ignore" */
/* */
/* Specify one or more net names to be ignored by the */
/* router. With no options, returns a list of nets */
/* being ignored by the router. */
/* */
/* Options: */
/* */
/* ignore [<net> ...] */
/*------------------------------------------------------*/
static int
qrouter_ignore(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int i;
NET net;
Tcl_Obj *lobj;
if (objc == 1) {
lobj = Tcl_NewListObj(0, NULL);
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (net->flags & NET_IGNORED) {
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(net->netname, -1));
}
}
Tcl_SetObjResult(interp, lobj);
}
else {
for (i = 1; i < objc; i++) {
net = LookupNet(Tcl_GetString(objv[i]));
if (net == NULL) {
Tcl_SetResult(interp, "No such net", NULL);
return TCL_ERROR;
}
net->flags |= NET_IGNORED;
}
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "priority" */
/* */
/* Specify one or more net names to be routed first by */
/* the router. With no options, returns a list of */
/* nets prioritized by the router. */
/* */
/* Options: */
/* */
/* priority [<net> ...] */
/*------------------------------------------------------*/
static int
qrouter_priority(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int i;
char *netname;
NET net;
STRING cn, ctest;
Tcl_Obj *lobj;
if (objc == 1) {
lobj = Tcl_NewListObj(0, NULL);
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (net->flags & NET_CRITICAL) {
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(net->netname, -1));
}
}
Tcl_SetObjResult(interp, lobj);
}
else {
for (i = objc - 1; i > 0; i--) {
netname = Tcl_GetString(objv[i]);
net = LookupNet(netname);
if (net == NULL) {
Tcl_SetResult(interp, "No such net", NULL);
}
else {
net->flags |= NET_CRITICAL;
for (cn = CriticalNet; cn && cn->next; cn = cn->next) {
if (!cn->next) break;
if (!strcmp(cn->next->name, netname)) {
ctest = cn->next;
cn->next = cn->next->next;
ctest->next = CriticalNet;
CriticalNet = ctest;
}
}
}
}
create_netorder(0);
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "layer_info" */
/* */
/* Provide information gleaned from the LEF technology */
/* file or files */
/* */
/* Options: */
/* */
/* layer_info [all] */
/* layer_info <layername>|<layernum> */
/* layer_info <layername>|<layernum> width */
/* layer_info <layername>|<layernum> pitch */
/* layer_info <layername>|<layernum> orientation */
/* layer_info <layername>|<layernum> offset */
/* layer_info <layername>|<layernum> spacing */
/* layer_info maxlayer */
/* */
/* all: generate a list summary of route information */
/* in the format of the info file generated with */
/* the "-i" command-line switch. */
/* <layer>: generate a list summary of information for */
/* the specified route layer <layer>, format the */
/* same as for option "all". */
/* <layer> pitch: Return the layer pitch value. */
/* <layer> orientation: Return the layer orientation. */
/* <layer> offset: Return the layer offset value. */
/* <layer> spacing: Return the layer minimum spacing */
/* value. */
/* maxlayer: Return the maximum number of route layers */
/* defined by the technology. */
/* */
/* No option is the same as option "layer_info all" */
/*------------------------------------------------------*/
static int
qrouter_layerinfo(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *lobj, *oobj;
int i, idx, idx2, val, result, layer = -1;
char *layername;
static char *subCmds[] = {
"all", "maxlayer", NULL
};
enum SubIdx {
AllIdx, MaxLayerIdx
};
static char *layerSubCmds[] = {
"width", "pitch", "orientation", "offset", "spacing", NULL
};
enum layerSubIdx {
WidthIdx, PitchIdx, OrientIdx, OffsetIdx, SpacingIdx
};
idx = idx2 = -1;
if (objc < 2) {
idx = AllIdx;
}
else {
layername = Tcl_GetString(objv[1]);
layer = LefFindLayerNum(layername);
if (layer == -1) {
if ((result = Tcl_GetIntFromObj(interp, objv[1], &val)) == TCL_OK) {
layer = val;
}
else {
Tcl_ResetResult(interp);
if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK) {
return result;
}
}
}
else if (objc >= 3) {
if ((result = Tcl_GetIndexFromObj(interp, objv[2],
(CONST84 char **)layerSubCmds, "option", 0, &idx2))
!= TCL_OK) {
return result;
}
layer = LefFindLayerNum(layername);
}
else {
layer = LefFindLayerNum(layername);
}
}
if (idx == -1 && layer == -1) {
Tcl_SetResult(interp, "Bad layer", NULL);
return TCL_ERROR;
}
if (layer < 0 || layer >= Num_layers) {
Tcl_SetResult(interp, "Bad layer", NULL);
return TCL_ERROR;
}
switch (idx) {
case AllIdx:
oobj = Tcl_NewListObj(0, NULL);
for (i = 0; i < Num_layers; i++) {
lobj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(LefGetRouteName(i), -1));
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewDoubleObj(LefGetRoutePitch(i)));
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewDoubleObj(LefGetRouteWidth(i)));
if (LefGetRouteOrientation(i) == 1)
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj("horizontal", -1));
else
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj("vertical", -1));
Tcl_ListObjAppendElement(interp, oobj, lobj);
}
Tcl_SetObjResult(interp, oobj);
break;
case MaxLayerIdx:
Tcl_SetObjResult(interp, Tcl_NewIntObj(Num_layers));
break;
}
switch (idx2) {
case WidthIdx:
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(LefGetRouteWidth(layer)));
break;
case PitchIdx:
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(LefGetRoutePitch(layer)));
break;
case OrientIdx:
if (LefGetRouteOrientation(layer) == (u_char)0)
Tcl_SetObjResult(interp, Tcl_NewStringObj("vertical", -1));
else
Tcl_SetObjResult(interp, Tcl_NewStringObj("horizontal", -1));
break;
case OffsetIdx:
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(LefGetRouteOffset(layer)));
break;
case SpacingIdx:
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(LefGetRouteSpacing(layer)));
break;
default:
if (idx != -1) break;
lobj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(LefGetRouteName(layer), -1));
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewDoubleObj(LefGetRoutePitch(layer)));
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewDoubleObj(LefGetRouteWidth(layer)));
if (LefGetRouteOrientation(layer) == 1)
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj("horizontal", -1));
else
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj("vertical", -1));
Tcl_SetObjResult(interp, lobj);
break;
}
return TCL_OK;
}
/*------------------------------------------------------*/
/* Command "via" */
/* */
/* Various via configuration options for qrouter. */
/* */
/* stack: Value is the maximum number of vias that may */
/* be stacked directly on top of each other at */
/* a single point. Value "none", "0", and "1" */
/* all mean the same thing. */
/* */
/* via_pattern: If vias are non-square, then they are */
/* placed in a checkerboard pattern, with every */
/* other via rotated 90 degrees. If inverted, */
/* the rotation is swapped relative to the grid */
/* positions used in the non-inverted case. */
/* */
/* use: List of names of vias to use. If any via not */
/* in this list is found when reading a .lef file */
/* it will be ignored. */
/* */
/* Options: */
/* */
/* via stack [none|all|<value>] */
/* via pattern [normal|inverted] */
/* via use <via_name> [<via_name> ...] */
/*------------------------------------------------------*/
static int
qrouter_via(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int idx, idx2, result, value, i;
char *vname;
Tcl_Obj *lobj;
LinkedStringPtr viaName, newVia;
static char *subCmds[] = {
"stack", "pattern", "use", NULL
};
enum SubIdx {
StackIdx, PatternIdx, UseIdx
};
static char *stackSubCmds[] = {
"none", "all", NULL
};
enum stackSubIdx {
NoneIdx, AllIdx
};
static char *patternSubCmds[] = {
"none", "normal", "inverted", NULL
};
enum patternSubIdx {
PatNoneIdx, PatNormalIdx, PatInvertIdx
};
if (objc >= 2) {
if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx))
!= TCL_OK)
return result;
if (objc == 2) {
switch (idx) {
case StackIdx:
Tcl_SetObjResult(interp, Tcl_NewIntObj(StackedContacts));
break;
case PatternIdx:
Tcl_SetObjResult(interp,
Tcl_NewStringObj(
patternSubCmds[ViaPattern + 1], -1));
break;
case UseIdx:
/* Return list of vias to use */
lobj = Tcl_NewListObj(0, NULL);
for (viaName = AllowedVias; viaName; viaName = viaName->next) {
Tcl_ListObjAppendElement(interp, lobj,
Tcl_NewStringObj(viaName->name, -1));
}
Tcl_SetObjResult(interp, lobj);
break;
}
}
else {
switch (idx) {
case StackIdx:
result = Tcl_GetIntFromObj(interp, objv[2], &value);
if (result == TCL_OK) {
if (value <= 0) value = 1;
else if (value >= Num_layers) value = Num_layers - 1;
StackedContacts = value;
break;
}
Tcl_ResetResult(interp);
if ((result = Tcl_GetIndexFromObj(interp, objv[2],
(CONST84 char **)stackSubCmds, "option",
0, &idx2)) != TCL_OK)
return result;
switch (idx2) {
case NoneIdx:
StackedContacts = 1;
break;
case AllIdx:
StackedContacts = Num_layers - 1;
break;
}
break;
case PatternIdx:
if ((result = Tcl_GetIndexFromObj(interp, objv[2],
(CONST84 char **)patternSubCmds, "option",
0, &idx2)) != TCL_OK)
return result;
ViaPattern = idx2 - 1;
break;
case UseIdx:
/* Create list of vias to use */
for (i = 2; i < objc; i++) {
vname = Tcl_GetString(objv[i]);
/* First check if name is in list already */
for (viaName = AllowedVias; viaName; viaName = viaName->next) {
if (!strcmp(vname, viaName->name))
break;
}
if (viaName != NULL) continue;
newVia = (LinkedStringPtr)malloc(sizeof(LinkedString));
newVia->name = strdup(vname);
newVia->next = AllowedVias;
AllowedVias = newVia;
}
/* Regenerate the ViaX and ViaY lists */
LefAssignLayerVias();
break;
}
}
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "verbose" */
/* */
/* Set the level of how much output to print to the */
/* console. 0 is minimal output, 4 is maximum output */
/* With no argument, return the level of verbose. */
/* */
/* Options: */
/* */
/* resolution [<value>] */
/*------------------------------------------------------*/
static int
qrouter_verbose(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int result, value;
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewIntObj(Verbose));
}
else if (objc == 2) {
result = Tcl_GetIntFromObj(interp, objv[1], &value);
if (result != TCL_OK) return result;
if (value < 0 || value > 255) {
Tcl_SetResult(interp, "Verbose level out of range", NULL);
return TCL_ERROR;
}
Verbose = (u_char)value;
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "resolution" */
/* */
/* Set the level of resolution of the output relative */
/* to the base units of centimicrons. The default */
/* value of 1 rounds all output values to the nearest */
/* centimicron; value 10 is to the nearest nanometer, */
/* and so forth. */
/* With no argument, return the value of the output */
/* resolution. */
/* */
/* Options: */
/* */
/* resolution [<value>] */
/*------------------------------------------------------*/
static int
qrouter_resolution(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int result, value;
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewIntObj(Scales.iscale));
}
else if (objc == 2) {
result = Tcl_GetIntFromObj(interp, objv[1], &value);
if (result != TCL_OK) return result;
if (value < 1) {
Tcl_SetResult(interp, "Resolution out of range", NULL);
return TCL_ERROR;
}
Scales.iscale = value;
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "layers" */
/* */
/* Set the number of layers used for routing */
/* independently of the number defined in the */
/* technology LEF file. Without an argument, return */
/* the number of layers being used (this is not the */
/* same as "layer_info maxlayer") */
/* */
/* Options: */
/* */
/* layers [<number>] */
/*------------------------------------------------------*/
static int
qrouter_layers(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int result, value;
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewIntObj(Num_layers));
}
else if (objc == 2) {
result = Tcl_GetIntFromObj(interp, objv[1], &value);
if (result != TCL_OK) return result;
if (value <= 0 || value > LefGetMaxLayer()) {
Tcl_SetResult(interp, "Number of layers out of range,"
" setting to max.", NULL);
Num_layers = LefGetMaxLayer();
return TCL_ERROR;
}
Num_layers = value;
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "passes" */
/* */
/* Set the maximum number of attempted passes of the */
/* route search algorithm, where the routing */
/* constraints (maximum cost and route area mask) are */
/* relaxed on each pass. */
/* With no argument, return the value for the maximum */
/* number of passes. */
/* The default number of passes is 10 and normally */
/* there is no reason for the user to change it. */
/* */
/* Options: */
/* */
/* passes [<number>] */
/*------------------------------------------------------*/
static int
qrouter_passes(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int result, value;
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewIntObj(Numpasses));
}
else if (objc == 2) {
result = Tcl_GetIntFromObj(interp, objv[1], &value);
if (result != TCL_OK) return result;
if (value <= 0) {
Tcl_SetResult(interp, "Number of passes out of range", NULL);
return TCL_ERROR;
}
Numpasses = value;
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "vdd" */
/* */
/* Set the name of the net used for VDD power routing */
/* With no argument, return the name of the power */
/* net. */
/* */
/* Options: */
/* */
/* vdd [<name>] */
/*------------------------------------------------------*/
static int
qrouter_vdd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
if (objc == 1) {
if (vddnet == NULL)
Tcl_SetObjResult(interp, Tcl_NewStringObj("(none)", -1));
else
Tcl_SetObjResult(interp, Tcl_NewStringObj(vddnet, -1));
}
else if (objc == 2) {
if (vddnet != NULL) free(vddnet);
vddnet = strdup(Tcl_GetString(objv[1]));
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "gnd" */
/* */
/* Set the name of the net used for ground routing. */
/* With no argument, return the name of the ground */
/* net. */
/* */
/* Options: */
/* */
/* gnd [<name>] */
/*------------------------------------------------------*/
static int
qrouter_gnd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
if (objc == 1) {
if (gndnet == NULL)
Tcl_SetObjResult(interp, Tcl_NewStringObj("(none)", -1));
else
Tcl_SetObjResult(interp, Tcl_NewStringObj(gndnet, -1));
}
else if (objc == 2) {
if (gndnet != NULL) free(gndnet);
gndnet = strdup(Tcl_GetString(objv[1]));
}
else {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "cost" */
/* */
/* Query or set the value of a cost function */
/* */
/* Options: */
/* */
/* cost segment */
/* cost via */
/* cost jog */
/* cost crossover */
/* cost block */
/* cost offset */
/* cost conflict */
/*------------------------------------------------------*/
static int
qrouter_cost(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int idx, result, value;
static char *subCmds[] = {
"segment", "via", "jog", "crossover",
"block", "offset", "conflict", NULL
};
enum SubIdx {
SegIdx, ViaIdx, JogIdx, XOverIdx, BlockIdx, OffsetIdx, ConflictIdx
};
value = 0;
if (objc == 3) {
result = Tcl_GetIntFromObj(interp, objv[2], &value);
if (result != TCL_OK) return result;
// Disallow negative costs.
if (value < 0) {
Tcl_SetResult(interp, "Bad cost value", NULL);
return TCL_ERROR;
}
}
else if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx)) != TCL_OK)
return result;
switch (idx) {
case SegIdx:
case ViaIdx:
case ConflictIdx:
// Segment, via, and conflict costs must not be zero or
// bad things happen.
if (value <= 0) {
Tcl_SetResult(interp, "Bad cost value", NULL);
return TCL_ERROR;
}
}
switch (idx) {
case SegIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(SegCost));
else
SegCost = value;
break;
case ViaIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(ViaCost));
else
ViaCost = value;
break;
case JogIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(JogCost));
else
JogCost = value;
break;
case XOverIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(XverCost));
else
XverCost = value;
break;
case OffsetIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(OffsetCost));
else
OffsetCost = value;
break;
case BlockIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(BlockCost));
else
BlockCost = value;
break;
case ConflictIdx:
if (objc == 2)
Tcl_SetObjResult(interp, Tcl_NewIntObj(ConflictCost));
else
ConflictCost = value;
break;
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
typedef struct clist_ *CLIST;
typedef struct clist_ {
GATE gate;
double congestion;
} Clist;
/*------------------------------------------------------*/
/* Compare function for qsort() */
/*------------------------------------------------------*/
int compcong(CLIST *a, CLIST *b)
{
CLIST p = *a;
CLIST q = *b;
if (p->congestion < q->congestion)
return (1);
else if (p->congestion > q->congestion)
return (-1);
else
return (0);
}
/*------------------------------------------------------*/
/* Command "congested" */
/* */
/* Return a list of instances, ranked by congestion. */
/* This list can be passed back to a placement tool to */
/* direct it to add padding around these cells to ease */
/* congestion and make the layout more routable. */
/* */
/* Options: */
/* */
/* congested <n> List the top <n> congested */
/* gates in the design. */
/*------------------------------------------------------*/
static int
qrouter_congested(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
NET net;
int i, x, y, nwidth, nheight, area, length;
int entries, numgates, result;
float density, *Congestion;
CLIST *cgates, csrch;
GATE gsrch;
struct seg_ bbox;
double dx, dy, cavg;
Tcl_Obj *lobj, *dobj;
if (objc == 2) {
result = Tcl_GetIntFromObj(interp, objv[1], &entries);
if (result != TCL_OK) return result;
if (entries <= 0) {
Tcl_SetResult(interp, "List size must be > 0", NULL);
return TCL_ERROR;
}
}
else
entries = 0;
Congestion = (float *)calloc(NumChannelsX[0] * NumChannelsY[0],
sizeof(float));
// Use net bounding boxes to estimate congestion
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
nwidth = (net->xmax - net->xmin + 1);
nheight = (net->ymax - net->ymin + 1);
area = nwidth * nheight;
if (nwidth > nheight) {
length = nwidth + (nheight >> 1) * net->numnodes;
}
else {
length = nheight + (nwidth >> 1) * net->numnodes;
}
density = (float)length / (float)area;
for (x = net->xmin; x < net->xmax; x++)
for (y = net->ymin; y < net->ymax; y++)
if (x >= 0 && x < NumChannelsX[0] &&
y >= 0 && y < NumChannelsY[0])
CONGEST(x, y) += density;
}
// Use instance bounding boxes to estimate average congestion
// in the area of an instance.
numgates = 0;
for (gsrch = Nlgates; gsrch; gsrch = gsrch->next) numgates++;
cgates = (CLIST *)malloc(numgates * sizeof(CLIST));
i = 0;
for (gsrch = Nlgates; gsrch; gsrch = gsrch->next) {
// Ignore pins, as the point of congestion planning
// is to add padding to the core instances; including
// pins just makes it harder for the placement script
// to process the information.
if (gsrch->gatetype == PinMacro) continue;
cgates[i] = (CLIST)malloc(sizeof(Clist));
dx = gsrch->placedX;
dy = gsrch->placedY;
bbox.x1 = (int)((dx - Xlowerbound) / PitchX[0]) - 1;
bbox.y1 = (int)((dy - Ylowerbound) / PitchY[0]) - 1;
dx = gsrch->placedX + gsrch->width;
dy = gsrch->placedY + gsrch->height;
bbox.x2 = (int)((dx - Xlowerbound) / PitchX[0]) - 1;
bbox.y2 = (int)((dy - Ylowerbound) / PitchY[0]) - 1;
cavg = 0.0;
for (x = bbox.x1; x <= bbox.x2; x++) {
for (y = bbox.y1; y <= bbox.y2; y++) {
cavg += CONGEST(x, y);
}
}
cavg /= (bbox.x2 - bbox.x1 + 1);
cavg /= (bbox.y2 - bbox.y1 + 1);
cgates[i]->gate = gsrch;
cgates[i++]->congestion = cavg / Num_layers;
}
// Re-set "numgates", because we have rejected pins from the
// original count.
numgates = i;
// Order Clist and copy contents back to the interpreter as a list
qsort((char *)cgates, numgates, (int)sizeof(CLIST), (__compar_fn_t)compcong);
lobj = Tcl_NewListObj(0, NULL);
if (entries == 0) entries = numgates;
else if (entries > numgates) entries = numgates;
for (i = 0; i < entries; i++) {
csrch = cgates[i];
gsrch = csrch->gate;
dobj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(interp, dobj,
Tcl_NewStringObj(gsrch->gatename, -1));
Tcl_ListObjAppendElement(interp, dobj,
Tcl_NewDoubleObj(csrch->congestion));
Tcl_ListObjAppendElement(interp, lobj, dobj);
}
Tcl_SetObjResult(interp, lobj);
// Cleanup
free(Congestion);
for (i = 0; i < numgates; i++) free(cgates[i]);
free(cgates);
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
/* Command "print" */
/* */
/* print an object */
/* */
/* Options: */
/* */
/* print net <netname> */
/* print netnr <netnumber> */
/* print gate <gatename> */
/*------------------------------------------------------*/
static int
qrouter_print(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
int idx, result, value;
NET net;
GATE gate;
static char *subCmds[] = {
"net", "netnr", "gate", NULL
};
enum SubIdx {
NetIdx, NetNrIdx, GateIdx
};
value = 0;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
return TCL_ERROR;
}
if ((result = Tcl_GetIndexFromObj(interp, objv[1],
(CONST84 char **)subCmds, "option", 0, &idx)) != TCL_OK)
return result;
switch (idx) {
case NetIdx:
net = LookupNet(Tcl_GetString(objv[2]));
if (net == NULL) {
Tcl_SetResult(interp, "Net not found", NULL);
return TCL_ERROR;
}
print_net(net);
break;
case NetNrIdx:
result = Tcl_GetIntFromObj(interp, objv[2], &value);
if (result != TCL_OK) return result;
net = LookupNetNr(value);
if (net == NULL) {
Tcl_SetResult(interp, "Net not found", NULL);
return TCL_ERROR;
}
print_net(net);
break;
case GateIdx:
gate = LookupGate(Tcl_GetString(objv[2]));
if (gate == NULL) {
Tcl_SetResult(interp, "Gate not found", NULL);
return TCL_ERROR;
}
print_gate(gate);
}
return QrouterTagCallback(interp, objc, objv);
}
/*------------------------------------------------------*/
|