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
|
/*
* defWrite.c --
*
* This module incorporates the LEF/DEF format for standard-cell place and
* route.
*
*
* Version 0.1 (June 9, 2004): DEF output for layouts, to include netlist
* from the extracted layout.
*
*/
#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-7.5/lef/defWrite.c,v 1.4 2008/02/10 19:06:32 tim Exp $";
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "tcltk/tclmagic.h"
#include "utils/magic.h"
#include "utils/geometry.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"
#include "utils/tech.h"
#include "utils/malloc.h"
#include "utils/undo.h"
#include "cif/cif.h"
#include "extflat/extflat.h"
#include "lef/lefInt.h"
#include "drc/drc.h" /* for querying width,spacing rules */
/*----------------------------------------------------------------------*/
/* Structures used by various routines */
/*----------------------------------------------------------------------*/
typedef struct {
float scale;
FILE *f;
CellDef *def;
Tile *tile; /* Values of the last calculated route */
TileType type;
float x, y, extlen;
unsigned char orient;
LefMapping *MagicToLefTbl;
int outcolumn; /* Current column of output in file */
unsigned char specialmode; /* What nets to write as SPECIALNETS */
} DefData;
typedef struct {
float scale;
int total;
int plane;
TileTypeBitMask *mask;
LefMapping *MagicToLefTbl;
} CViaData;
/*----------------------------------------------------------------------*/
char *defGetType(); /* Forward declaration */
/*----------------------------------------------------------------------*/
/*
* ----------------------------------------------------------------------------
*
* defWriteHeader --
*
* This routine generates DEF header output for a cell or cell hierarchy.
*
* Results:
* None.
*
* Side effects:
* Writes output to the open file "f".
*
* ----------------------------------------------------------------------------
*/
void
defWriteHeader(def, f, oscale)
CellDef *def; /* Def for which to generate DEF output */
FILE *f; /* Output to this file */
float oscale;
{
TileType type;
TxPrintf("Diagnostic: Write DEF header for cell %s\n", def->cd_name);
/* NOTE: This routine corresponds to Envisia LEF/DEF Language */
/* Reference version 5.3 (May 31, 2000) */
fprintf(f, "VERSION 5.3 ;\n");
fprintf(f, " NAMESCASESENSITIVE ON ;\n");
fprintf(f, " DIVIDERCHAR \"/\" ;\n");
/* Declare that buses are denoted with parentheses, since magic */
/* uses brackets for arrays and instances. */
fprintf(f, " BUSBITCHARS \"()\" ;\n");
/* Design name, taken from the cell def name */
fprintf(f, " DESIGN %s ;\n", def->cd_name);
/* Technology name, taken from the magic tech file. */
/* (which may not be a good idea. . . may need a tech definition */
/* in the tech file "lef" section to specifically name the LEF/DEF */
/* technology). */
fprintf(f, " TECHNOLOGY %s ;\n", DBTechName);
/* As I understand it, this refers to the scalefactor of the GDS */
/* file output. Magic does all GDS in nanometers, so the LEF */
/* scalefactor (conversion to microns) is always 1000. */
fprintf(f, " UNITS DISTANCE MICRONS 1000 ;\n");
/* Die area, taken from the cell def bounding box. */
fprintf(f, " DIEAREA ( %.10g %.10g ) ( %.10g %.10g ) ;\n",
(float)def->cd_bbox.r_xbot * oscale,
(float)def->cd_bbox.r_ybot * oscale,
(float)def->cd_bbox.r_xtop * oscale,
(float)def->cd_bbox.r_ytop * oscale);
fprintf(f, "\n");
}
/*
*------------------------------------------------------------
*
* defTransPos --
*
* Determine the DEF orientation of a specific magic
* transformation matrix.
*
* Results:
* The position, in DEF string format ("N" for north, etc.)
* This is a static string
*
* Side Effects:
* None.
*
*------------------------------------------------------------
*/
char *
defTransPos(Transform *t)
{
static char *def_orient[] = {
"N", "S", "E", "W", "FN", "FS", "FE", "FW"
};
bool ew; /* east-or-west identifier */
bool sw; /* south-or-west identifier */
bool flip;
int pos = 0;
ew = ((t->t_a == 0) && (t->t_e == 0)) ? TRUE : FALSE;
if (ew)
{
flip = ((t->t_b * t->t_d) > 0) ? TRUE : FALSE;
sw = (t->t_d > 0) ? TRUE : FALSE;
}
else
{
flip = ((t->t_a * t->t_e) < 0) ? TRUE : FALSE;
sw = (t->t_e > 0) ? FALSE : TRUE;
}
if (flip) pos += 4;
if (ew) pos += 2;
if (sw) pos += 1;
return def_orient[pos];
}
/*
*------------------------------------------------------------
*
* defCountNets --
*
* First-pass function to count the number of different
* nets used. If "allSpecial" is TRUE, consider all
* geometry to be SPECIALNETS.
*
* Results:
* A NetCount structure holding the regular and special
* net totals upon completion.
*
* Side Effects:
* None.
*
*------------------------------------------------------------
*/
NetCount
defCountNets(rootDef, allSpecial)
CellDef *rootDef;
bool allSpecial;
{
NetCount total;
int defnodeCount();
total.regular = (allSpecial) ? -1 : 0;
total.special = 0;
total.has_nets = TRUE;
TxPrintf("Diagnostic: Finding all nets in cell %s\n", rootDef->cd_name);
TxPrintf("(This can take a while!)\n");
/* Read in the extracted file */
EFInit();
/* There are no arguments for extflat, but we need to call the */
/* routine to initialize a few things such as the search path. */
EFArgs(0, NULL, NULL, NULL, NULL);
EFScale = 0.0; /* Allows EFScale to be set to the scale value */
if (EFReadFile(rootDef->cd_name, TRUE, FALSE, TRUE))
{
EFFlatBuild(rootDef->cd_name, EF_FLATNODES | EF_NOFLATSUBCKT);
EFVisitNodes(defnodeCount, (ClientData)&total);
}
else
{
TxError("Warning: Circuit has no .ext file; no nets written.\n");
TxError("Run extract on this circuit if you want nets in the output.\n");
EFDone();
total.has_nets = FALSE;
}
if (allSpecial) total.regular = 0;
return total;
}
/* Callback function used by defCountNets */
int
defnodeCount(node, res, cap, total)
EFNode *node;
int res; /* not used */
EFCapValue cap; /* not used */
NetCount *total;
{
HierName *hierName;
char ndn[256];
char *cp, clast;
/* Ignore power and ground lines, which we will treat */
/* as SPECIALNETS types. */
hierName = (HierName *) node->efnode_name->efnn_hier;
if (!(hierName->hn_parent)) /* Extra processing of top-level nodes */
{
char *pwr;
cp = hierName->hn_name;
clast = *(cp + strlen(cp) - 1);
/* Global nodes are marked as "special nets" */
if (clast == '!')
node->efnode_flags |= EF_SPECIAL;
#ifdef MAGIC_WRAPPER
/* Check if name is defined in array "globals" */
pwr = (char *)Tcl_GetVar2(magicinterp, "globals", cp, TCL_GLOBAL_ONLY);
if (pwr)
{
/* Diagnostic */
TxPrintf("Node %s is defined in the \"globals\" array\n");
node->efnode_flags |= EF_SPECIAL;
}
/* Check against Tcl variables $VDD and $GND */
pwr = (char *)Tcl_GetVar(magicinterp, "VDD", TCL_GLOBAL_ONLY);
if (pwr && (!strcmp(cp, pwr)))
{
/* Diagnostic */
TxPrintf("Node %s matches VDD variable definition!\n");
node->efnode_flags |= EF_SPECIAL;
}
pwr = (char *)Tcl_GetVar(magicinterp, "GND", TCL_GLOBAL_ONLY);
if (pwr && (!strcmp(cp, pwr)))
{
/* Diagnostic */
TxPrintf("Node %s matches GND variable definition!\n");
node->efnode_flags |= EF_SPECIAL;
}
/* If a node has not been marked as SPECIAL, does not connect */
/* to a port, and does not have an internally-generated name, */
/* then mark it as "special". */
if (!(node->efnode_flags & (EF_SPECIAL | EF_PORT)) &&
(clast != '#'))
node->efnode_flags |= EF_SPECIAL;
#endif
}
if (total->regular < 0)
{
/* "allspecial" options: all nets written as SPECIALNETS */
if ((node->efnode_flags & EF_SPECIAL) || (node->efnode_flags & EF_PORT))
total->special++;
}
else
{
/* We only count nodes having a port connection as "regular" nets */
if (node->efnode_flags & EF_SPECIAL)
total->special++;
else if (node->efnode_flags & EF_PORT)
total->regular++;
}
return 0; /* Keep going. . . */
}
/*
* ----------------------------------------------------------------------------
*
* defHNsprintf --
*
* Create a hierarchical node name for the DEF output file..
*
* Results:
* None.
*
* Side effects:
* Changes the area pointed to by str
*
* ----------------------------------------------------------------------------
*/
void
defHNsprintf(str, hierName, divchar)
char *str;
HierName *hierName;
char divchar;
{
bool trimGlob, trimLocal;
char *s, *cp, c;
char *defHNsprintfPrefix();
s = str;
if (hierName->hn_parent) str = defHNsprintfPrefix(hierName->hn_parent, str,
divchar);
/* Make the name conform to valid LEF/DEF syntax. This means */
/* no pound signs or semicolons (which are illegal characters, */
/* along with space and newline which won't be found in the */
/* magic name anyway), or dashes, asterisks, or percent signs */
/* (which are interpreted as wildcard characters by LEF/DEF). */
cp = hierName->hn_name;
while (c = *cp++)
{
switch (c)
{
case '#': /* Ignore---this is the final character */
/* in internally-generated node names. */
break;
case ';':
case '-':
case '*':
case '%':
*str++ = '_';
break;
default:
*str++ = c;
break;
}
}
*str++ = '\0';
}
char *defHNsprintfPrefix(hierName, str, divchar)
HierName *hierName;
char *str;
char divchar;
{
char *cp, c;
if (hierName->hn_parent)
str = defHNsprintfPrefix(hierName->hn_parent, str);
cp = hierName->hn_name;
while (*str++ = *cp++) ;
*(--str) = divchar;
return ++str;
}
/*
*------------------------------------------------------------
*
* nodeDefName ---
*
* Determine the node name to write to the DEF file
* for the given hierachical name structure from
* extflat.
*
*------------------------------------------------------------
*/
char *
nodeDefName(hname)
HierName *hname;
{
EFNodeName *nn;
HashEntry *he;
EFNode *node;
static char nodeName[256];
he = EFHNLook(hname, (char *) NULL, "nodeName");
if (he == NULL)
return "errorNode";
nn = (EFNodeName *) HashGetValue(he);
node = nn->efnn_node;
defHNsprintf(nodeName, node->efnode_name->efnn_hier, '/');
return nodeName;
}
/*
*------------------------------------------------------------
*
* defCheckForBreak --
*
* Add the number "addlen" to the column value of
* the output. If the DEF file output has reached or
* exceeds this value, write a newline character to
* the output and reset the column count.
*
* Results:
* None.
*
* Side effects:
* Output to DEF file; resets defdata->outcolumn
*
*------------------------------------------------------------
*/
#define MAX_DEF_COLUMNS 70
void
defCheckForBreak(addlen, defdata)
int addlen;
DefData *defdata;
{
defdata->outcolumn += addlen;
if (defdata->outcolumn > MAX_DEF_COLUMNS)
{
fprintf(defdata->f, "\n ");
defdata->outcolumn = 6 + addlen;
}
}
/*
*------------------------------------------------------------
*
* defWriteRouteWidth ---
*
* Write the width of a SPECIALNET route to the output.
*
*------------------------------------------------------------
*/
void
defWriteRouteWidth(defdata, width)
DefData *defdata;
int width;
{
float oscale = defdata->scale;
char numstr[12];
sprintf(numstr, "%.10g", ((float)width * defdata->scale));
defCheckForBreak(strlen(numstr) + 1, defdata);
fprintf(defdata->f, "%s ", numstr);
}
/*
*------------------------------------------------------------
*
* defWriteCoord --
*
* Output a coordinate pair in DEF syntax. We supply the
* point to be written AND the previously written point
* so we can make use of the "*" notation in the DEF point
* format. If the point to be written is not an extension
* of the previous point, "prevpt" should be NULL.
*
* Results:
* None.
*
* Side Effects:
* Output written to the DEF file.
*
*------------------------------------------------------------
*/
void
defWriteCoord(defdata, x, y, orient)
DefData *defdata;
float x, y;
unsigned char orient;
{
FILE *f = defdata->f;
char numstr[12];
int ctot = 4;
/* The "12" here is just a fudge factor; it is not crucial */
/* to limit the output to exactly MAX_DEF_COLUMNS, and it */
/* is easier to assume that the output of a coordinate */
/* pair is about 12 characters average rather than try to */
/* predetermine what the actual output length will be. */
if ((defdata->outcolumn + 12) > MAX_DEF_COLUMNS)
{
fprintf(f, "\n ");
defdata->outcolumn = 6;
}
fprintf(f, " ( ");
if ((orient == GEO_NORTH) || (orient == GEO_SOUTH))
{
fprintf(f, "* ");
ctot += 2;
}
else
{
sprintf(numstr, "%.10g", x);
fprintf(f, "%s ", numstr);
ctot += strlen(numstr) + 1;
}
if ((orient == GEO_EAST) || (orient == GEO_WEST))
{
fprintf(f, "* ");
ctot += 2;
}
else
{
sprintf(numstr, "%.10g", y);
fprintf(f, "%s ", numstr);
ctot += strlen(numstr) + 1;
}
fprintf(f, ")");
defdata->outcolumn += ctot;
}
/*
*------------------------------------------------------------
*
* defWriteNets --
*
* Output the NETS section of a DEF file. We make use of
* the connectivity search routines used by "getnode" to
* determine unique notes and assign a net name to each.
* Then, we generate the geometry output for each NET
* entry.
*
* Results:
* None.
*
* Side Effects:
* Output written to the DEF output file.
*
*------------------------------------------------------------
*/
void
defWriteNets(f, rootDef, oscale, MagicToLefTable, specialmode)
FILE *f; /* File to write to */
CellDef *rootDef; /* Cell definition to use */
float oscale; /* Output scale factor */
LefMapping *MagicToLefTable; /* Magic to LEF layer mapping */
unsigned char specialmode; /* What to write as a SPECIALNET */
{
DefData defdata;
int defnodeVisit();
defdata.f = f;
defdata.scale = oscale;
defdata.def = rootDef;
defdata.MagicToLefTbl = MagicToLefTable;
defdata.outcolumn = 0;
defdata.specialmode = specialmode;
EFVisitNodes(defnodeVisit, (ClientData)&defdata);
}
int
defnodeVisit(node, res, cap, defdata)
EFNode *node;
int res;
EFCapValue cap;
DefData *defdata;
{
HierName *hierName;
char *ndn;
char ndn2[256];
FILE *f = defdata->f;
CellDef *def = defdata->def;
float oscale = defdata->scale;
TileTypeBitMask tmask, *rmask;
TileType magictype;
EFNodeName *thisnn;
int defNetGeometryFunc(); /* Forward declaration */
/* For regular nets, only count those nodes having port */
/* connections. For special nets, only count those nodes */
/* that were marked with the EF_SPECIAL flag while counting */
/* nets. */
if (defdata->specialmode == DO_REGULAR)
{
if (!(node->efnode_flags & EF_PORT))
return 0;
}
else if (defdata->specialmode == DO_SPECIAL)
{
if (!(node->efnode_flags & EF_SPECIAL))
return 0;
}
else /* ALL_SPECIAL */
{
if (!(node->efnode_flags & EF_PORT) &&
!(node->efnode_flags & EF_SPECIAL))
return 0;
}
hierName = (HierName *) node->efnode_name->efnn_hier;
ndn = nodeDefName(hierName);
defHNsprintf(ndn2, node->efnode_name->efnn_hier, '/');
if (strcmp(ndn, ndn2))
{
TxError("Node mismatch: %s vs. %s\n", ndn, ndn2);
}
fprintf(f, " - %s", ndn);
defdata->outcolumn = 5 + strlen(ndn);
/* Find all the node names that are port connections. */
/* For now, we will just use anything connecting one level */
/* down in the hierarchy. This is not definitive, however, */
/* and we should confirm that the connection is an actual */
/* port. */
for (thisnn = node->efnode_name; thisnn != NULL; thisnn = thisnn->efnn_next)
{
char locndn[256];
hierName = thisnn->efnn_hier;
if (hierName->hn_parent && !hierName->hn_parent->hn_parent)
{
/* This is just another kludgy check for a non-port and */
/* will eventually be removed. */
char endc = *(hierName->hn_name + strlen(hierName->hn_name) - 1);
if (endc != '#')
{
defHNsprintf(locndn, thisnn->efnn_hier, ' ');
defCheckForBreak(5 + strlen(locndn), defdata);
fprintf(f, " ( %s )", locndn);
}
}
}
/* TT_SPACE indicates that a layer name must be the next */
/* thing to be written to the DEF file. */
defdata->type = TT_SPACE;
defdata->tile = (Tile *)NULL;
/* Net geometry (this should be an option!)--- */
/* Use the DBconnect routines to find all geometry */
/* connected to a specific node. This is a */
/* redundant search---we've already done this once */
/* when extracting the circuit. But, because the */
/* DEF file requires a count of nodes up front, we */
/* would have to do it twice anyway. In this case, */
/* we only do it once here, since the results of */
/* the first pass are picked up from the .ext file. */
magictype = DBTechNameType(EFLayerNames[node->efnode_type]);
/* Note that the type of the node might be defined by the type */
/* in the subcircuit itself, so we need to search for any type */
/* that might validly connect to it, not just the type itself. */
/* TTMaskSetOnlyType(&tmask, magictype); */
TTMaskZero(&tmask);
TTMaskSetMask(&tmask, &DBConnectTbl[magictype]);
DBSrConnect(def, &node->efnode_loc, &tmask, DBConnectTbl,
&TiPlaneRect, defNetGeometryFunc,
(ClientData)defdata);
if (defdata->tile == (Tile *)NULL)
{
/* No route layer? It's possible that something connects to */
/* the port location but doesn't overlap. Try painting the */
/* node type in def and trying again. */
Rect rport;
SearchContext scx;
int defPortTileFunc(); /* Fwd declaration */
scx.scx_area = node->efnode_loc;
scx.scx_use = def->cd_parents;
scx.scx_trans = GeoIdentityTransform;
DBTreeSrUniqueTiles(&scx, &tmask, 0, defPortTileFunc, (ClientData)&rport);
/* Add the residue types to any contact type */
if (DBIsContact(magictype))
{
rmask = DBResidueMask(magictype);
TTMaskSetMask(&tmask, rmask);
TTMaskSetType(&tmask, magictype);
}
/* Expand the rectangle around the port to overlap any */
/* connecting material. */
rport.r_xbot--;
rport.r_ybot--;
rport.r_xtop++;
rport.r_ytop++;
DBSrConnect(def, &rport, &tmask, DBConnectTbl, &TiPlaneRect,
defNetGeometryFunc, (ClientData)defdata);
}
/* Was there a last record pending? If so, write it. */
if (defdata->tile != (Tile *)NULL)
{
if (defdata->orient != GEO_CENTER)
defWriteCoord(defdata, defdata->x, defdata->y, defdata->orient);
defdata->outcolumn = 0;
}
fprintf(f, " ;\n");
return 0; /* Keep going */
}
/* Callback function for DBTreeSrUniqueTiles. When no routed areas */
/* were found, we assume that there was no routing material overlapping */
/* the port. So, we need to find the area of a tile defining the port */
/* so we can look for attaching material. */
int
defPortTileFunc(tile, cx)
Tile *tile;
TreeContext *cx;
{
SearchContext *scx = cx->tc_scx;
Rect *rport = (Rect *)cx->tc_filter->tf_arg;
Rect r;
TiToRect(tile, &r);
GeoTransRect(&scx->scx_trans, &r, rport);
/* Diagnostic */
/*
TxPrintf("Port tile at (%d %d) to (%d %d)\n",
rport->r_xbot, rport->r_ybot,
rport->r_xtop, rport->r_ytop);
*/
return 1; /* No need to check further */
}
/* Callback function for writing geometry of the network to */
/* the DEF file. */
int
defNetGeometryFunc(tile, plane, defdata)
Tile *tile; /* Tile being visited */
int plane; /* Plane of the tile being visited */
DefData *defdata; /* Data passed to this function */
{
FILE *f = defdata->f;
CellDef *def = defdata->def;
float oscale = defdata->scale;
TileTypeBitMask *rMask, *r2Mask;
TileType rtype, r2type, ttype = TiGetType(tile);
Rect r;
unsigned char orient;
bool sameroute = FALSE;
int routeWidth, w, h, midlinex2;
float x1, y1, x2, y2, extlen;
lefLayer *lefType;
char *lefName, viaName[20];
LefMapping *MagicToLefTable = defdata->MagicToLefTbl;
TiToRect(tile, &r);
/* Treat contacts here exactly the same way as defCountVias */
if (DBIsContact(ttype))
{
Rect r2;
Tile *tp;
rMask = NULL;
if (ttype >= DBNumUserLayers)
{
/* Stacked contact types need to be broken into their */
/* constituent types. Process only if we are on the home */
/* plane of one of the constituent types. */
rMask = DBResidueMask(ttype);
for (rtype = TT_TECHDEPBASE; rtype < DBNumUserLayers; rtype++)
if (TTMaskHasType(rMask, rtype))
if (DBPlane(rtype) == plane)
{
ttype = rtype;
break;
}
if (rtype == DBNumUserLayers)
return 0;
}
else
if (DBPlane(ttype) != plane)
return 0;
/* Boundary search on stacked contact types to include any */
/* tile areas belonging to ttype. */
for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp = BL(tp)) /* Top */
{
r2type = TiGetBottomType(tp);
if (r2type == ttype)
{
if (!rMask) return 0;
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (r2type >= DBNumUserLayers)
{
r2Mask = DBResidueMask(r2type);
if (TTMaskHasType(r2Mask, ttype))
return 0;
}
}
for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp = RT(tp)) /* Left */
{
r2type = TiGetRightType(tp);
if (r2type == ttype)
{
if (!rMask) return 0;
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (r2type >= DBNumUserLayers)
{
r2Mask = DBResidueMask(r2type);
if (TTMaskHasType(r2Mask, ttype))
return 0;
}
}
for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp = TR(tp)) /* Bottom */
{
r2type = TiGetTopType(tp);
if (r2type == ttype)
{
if (!rMask) return 0;
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (r2type >= DBNumUserLayers)
{
r2Mask = DBResidueMask(r2type);
if (TTMaskHasType(r2Mask, ttype))
return 0;
}
}
for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp = LB(tp)) /* Right */
{
r2type = TiGetLeftType(tp);
if (r2type == ttype)
{
if (!rMask) return 0;
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (r2type >= DBNumUserLayers)
{
r2Mask = DBResidueMask(r2type);
if (TTMaskHasType(r2Mask, ttype))
return 0;
}
}
}
/* Layer names are taken from the LEF database. */
lefName = MagicToLefTable[ttype].lefName;
lefType = MagicToLefTable[ttype].lefInfo;
orient = GEO_EAST;
w = r.r_xtop - r.r_xbot;
h = r.r_ytop - r.r_ybot;
midlinex2 = (r.r_ytop + r.r_ybot);
if (defdata->specialmode != DO_REGULAR)
{
routeWidth = (h > w) ? w : h;
if ((lefType && lefType->lefClass == CLASS_VIA)
|| (!lefType && DBIsContact(ttype)))
orient = GEO_CENTER;
}
else
{
routeWidth = 0;
if ((lefType && (lefType->lefClass == CLASS_VIA))
|| (!lefType && DBIsContact(ttype)))
orient = GEO_CENTER;
else if (lefType)
routeWidth = lefType->info.route.width;
if (routeWidth == 0)
routeWidth = DRCGetDefaultLayerWidth(ttype);
}
if (orient != GEO_CENTER) /* not a via type */
{
if (h != routeWidth)
{
if ((w == routeWidth) || ((routeWidth == 0) && (h > w)))
{
orient = GEO_NORTH;
midlinex2 = (r.r_xtop + r.r_xbot);
}
}
/* Warn if the route is not equal to the default route width--- */
/* This means a regular net should have been a special net. */
if ((h != routeWidth) && (w != routeWidth))
{
/* Diagnostic */
TxPrintf("Net has width %d, default width is %d\n",
(h > w) ? h : w, routeWidth);
}
/* Find the route orientation and centerline endpoint coordinates */
if (orient == GEO_EAST)
{
y1 = (midlinex2 * oscale) / 2;
y2 = y1;
x1 = r.r_xbot * oscale;
x2 = r.r_xtop * oscale;
if (routeWidth == 0) routeWidth = h;
extlen = (defdata->specialmode != DO_REGULAR) ?
0 : (routeWidth * oscale) / 2;
}
else /* vertical orientation */
{
x1 = (midlinex2 * oscale) / 2;
x2 = x1;
y1 = r.r_ybot * oscale;
y2 = r.r_ytop * oscale;
if (routeWidth == 0) routeWidth = w;
extlen = (defdata->specialmode != DO_REGULAR) ?
0 : (routeWidth * oscale) / 2;
}
}
else /* Type is a via */
{
y1 = y2 = (midlinex2 * oscale) / 2;
x1 = x2 = ((r.r_xtop + r.r_xbot) * oscale) / 2;
extlen = 0;
}
/* For contact types, find the residues of the contact */
if (orient == GEO_CENTER)
{
TileType stype;
rtype = r2type = TT_SPACE;
rMask = DBResidueMask(ttype);
for (stype = TT_TECHDEPBASE; stype < DBNumUserLayers; stype++)
{
if (TTMaskHasType(rMask, stype))
{
if ((stype == defdata->type) || (defdata->tile == (Tile *)NULL))
rtype = stype;
else
r2type = stype;
}
}
}
/* If we previously visited a tile, write out its second */
/* coordinate pair, adjusting the position if necessary to */
/* make the wire extensions line up correctly. If they */
/* don't line up, we assume a dogleg route and add */
/* coordinate pairs as necessary to generate the correct */
/* geometry in the DEF output. */
if (defdata->tile)
{
Rect r2;
TiToRect(defdata->tile, &r2);
/* Only consider the endpoint of the previous tile at X2,Y2 */
/* And the endpoint of the current tile at X1,Y1 */
if (defdata->orient == GEO_EAST)
r2.r_xbot = r2.r_xtop - 1;
else if (defdata->orient == GEO_NORTH)
r2.r_ybot = r2.r_ytop - 1;
if (orient == GEO_EAST)
r.r_xtop = r.r_xbot + 1;
else if (orient == GEO_NORTH)
r.r_ytop = r.r_ybot + 1;
/* "sameroute" is true only if rectangles touch in the */
/* direction of the route. */
/* NOTE: We should compute this FIRST and use it to determine */
/* the current route direction! */
/* Another hack---for special nets, don't continue routes that */
/* have different widths, even if they're connected in the */
/* direction of travel. A separate record will be written for */
/* the segment of different width. */
if (GEO_TOUCH(&r, &r2))
{
if (defdata->orient == GEO_EAST)
{
if ((r.r_xbot == r2.r_xtop) || (r.r_xtop == r2.r_xbot))
{
sameroute = TRUE;
if ((defdata->specialmode != DO_REGULAR) &&
(r.r_ytop != r2.r_ytop || r.r_ybot != r2.r_ybot))
sameroute = FALSE;
}
}
else if (defdata->orient == GEO_NORTH)
{
if ((r.r_ybot == r2.r_ytop) || (r.r_ytop == r2.r_ybot))
{
sameroute = TRUE;
if ((defdata->specialmode != DO_REGULAR) &&
(r.r_xtop != r2.r_xtop || r.r_xbot != r2.r_xbot))
sameroute = FALSE;
}
}
else
sameroute = TRUE;
}
/* We should NOT continue a route from a via for a special net, */
/* because the spec for this situation is too vaguely defined. */
if (sameroute && (defdata->specialmode != DO_REGULAR) &&
defdata->orient == GEO_CENTER)
sameroute = FALSE;
}
/* Determine if we need to write a NEW (type) record. We do this */
/* if 1) this is the first tile visited (except that we don't */
/* write "NEW"), 2) the current tile doesn't touch the last tile */
/* visited, or 3) the current type is not equal to the last type. */
if ((!sameroute) || (ttype != defdata->type))
{
/* This is not a continuation of the last route. Output */
/* the last route position, and start a NEW record. */
if ((sameroute) && (ttype != defdata->type) &&
(orient == GEO_CENTER) &&
(rtype == defdata->type))
{
/* Adjust previous route to centerpoint of the via. If the */
/* via is not centered on the route, add segments to create */
/* the proper alignment. */
if ((defdata->orient == GEO_NORTH) && (x1 == defdata->x))
defWriteCoord(defdata, defdata->x, y1, defdata->orient);
else if ((defdata->orient == GEO_EAST) && (y1 == defdata->y))
defWriteCoord(defdata, x1, defdata->y, defdata->orient);
else if (defdata->orient == GEO_EAST)
{
defWriteCoord(defdata, x1, defdata->y, defdata->orient);
defWriteCoord(defdata, x1, y1, GEO_NORTH);
}
else if (defdata->orient == GEO_NORTH)
{
defWriteCoord(defdata, defdata->x, y1, defdata->orient);
defWriteCoord(defdata, x1, y1, GEO_EAST);
}
/* Via type continues route */
sprintf(viaName, "_%.10g_%.10g",
((float)w * oscale), ((float)h * oscale));
defCheckForBreak(strlen(lefName) + strlen(viaName) + 2, defdata);
fprintf(f, " %s%s ", lefName, viaName);
}
else
{
/* New route segment. Complete the last route segment. */
if (defdata->tile)
{
/* Don't write out a segment for a via */
if (defdata->orient != GEO_CENTER)
defWriteCoord(defdata,
defdata->x - ((defdata->orient == GEO_EAST) ?
defdata->extlen : 0),
defdata->y - ((defdata->orient == GEO_NORTH) ?
defdata->extlen : 0), defdata->orient);
fprintf(f, "\n NEW ");
defdata->outcolumn = 10;
}
else
{
/* First record printed for this node */
fprintf(f, "\n + ROUTED ");
defdata->outcolumn = 15;
}
/* This is the first tile segment visited in the */
/* current type---use GEO_CENTER so that no */
/* coordinate wildcards ("*") get written. */
if (orient == GEO_CENTER)
{
char *rName;
/* Type can be zero (space) if the first tile */
/* encountered is a via. If so, use the 1st */
/* residue of the contact as the route layer */
/* type. */
rName = defGetType((rtype == TT_SPACE) ? r2type : rtype, NULL);
/* The first layer in a record may not be a via name */
defCheckForBreak(strlen(rName) + 1, defdata);
fprintf(f, "%s ", rName);
if (defdata->specialmode != DO_REGULAR)
defWriteRouteWidth(defdata, routeWidth);
defWriteCoord(defdata, x1, y1, GEO_CENTER);
sprintf(viaName, "_%.10g_%.10g",
((float)w * oscale), ((float)h * oscale));
defCheckForBreak(strlen(lefName) + strlen(viaName) + 2, defdata);
fprintf(f, " %s%s ", lefName, viaName);
}
else
{
defCheckForBreak(strlen(lefName) + 1, defdata);
fprintf(f, "%s ", lefName);
if (defdata->specialmode != DO_REGULAR)
defWriteRouteWidth(defdata, routeWidth);
/* defWriteCoord(defdata, x1, y1, GEO_CENTER); */
defWriteCoord(defdata,
x1 + ((orient == GEO_EAST) ? extlen : 0),
y1 + ((orient == GEO_NORTH) ? extlen : 0),
GEO_CENTER);
}
}
}
else if (sameroute)
{
/* Adjust the previous route segment to match the new segment, */
/* and write out the previous route segment record. */
if ((orient == defdata->orient) && (defdata->x != x1) && (defdata->y != x2))
{
/* Dogleg---insert extra segment */
defWriteCoord(defdata,
defdata->x - ((defdata->orient == GEO_EAST) ?
defdata->extlen : 0),
defdata->y - ((defdata->orient == GEO_NORTH) ?
defdata->extlen : 0), defdata->orient);
defWriteCoord(defdata, x1 + ((orient == GEO_EAST) ? extlen : 0),
y1 + ((orient == GEO_NORTH) ? extlen : 0), orient);
}
else
{
if (defdata->orient == GEO_EAST)
{
if (((defdata->x + defdata->extlen) == x1) ||
((defdata->x - defdata->extlen) == x1))
defWriteCoord(defdata, x1, defdata->y, defdata->orient);
else
{
/* Don't know how to connect the route segments. */
/* End the original route and start a new one. */
defWriteCoord(defdata,
defdata->x - ((defdata->orient == GEO_EAST) ?
defdata->extlen : 0),
defdata->y - ((defdata->orient == GEO_NORTH) ?
defdata->extlen : 0), defdata->orient);
fprintf(f, "\n NEW %s", lefName);
defdata->outcolumn = 10 + strlen(lefName);
if (defdata->specialmode != DO_REGULAR)
{
fprintf(f, " ");
defdata->outcolumn++;
defWriteRouteWidth(defdata, routeWidth);
}
defWriteCoord(defdata,
x1 + ((orient == GEO_EAST) ? extlen : 0),
y1 + ((orient == GEO_NORTH) ? extlen : 0),
GEO_CENTER);
}
}
else if (defdata->orient == GEO_NORTH)
{
if (((defdata->y + defdata->extlen) == y1) ||
((defdata->y - defdata->extlen) == y1))
defWriteCoord(defdata, defdata->x, y1, defdata->orient);
else
{
/* Don't know how to connect the route segments. */
/* End the original route and start a new one. */
defWriteCoord(defdata,
defdata->x - ((defdata->orient == GEO_EAST) ?
defdata->extlen : 0),
defdata->y - ((defdata->orient == GEO_NORTH) ?
defdata->extlen : 0), defdata->orient);
fprintf(f, "\n NEW %s", lefName);
if (defdata->specialmode != DO_REGULAR) {
fprintf(f, " ");
defdata->outcolumn++;
defWriteRouteWidth(defdata, routeWidth);
}
defdata->outcolumn = 10 + strlen(lefName);
defWriteCoord(defdata,
x1 + ((orient == GEO_EAST) ? extlen : 0),
y1 + ((orient == GEO_NORTH) ? extlen : 0),
GEO_CENTER);
}
}
else /* last record was a via */
{
/* Continuing route from via to other connecting layer type */
/* Bend to meet via center---insert extra segment */
if ((orient == GEO_NORTH) && (x1 != defdata->x))
defWriteCoord(defdata, x1, defdata->y, GEO_EAST);
else if ((orient == GEO_EAST) && (y1 != defdata->y))
defWriteCoord(defdata, defdata->x, y1, GEO_NORTH);
}
}
}
/* After a contact type, the route coordinates may continue in the */
/* routing type connected by the contact to the type that was */
/* previously seen connected to the contact. */
/* NOTE! The above comment matches the example on page 203 of the */
/* LEF/DEF reference manual. However, it is obvious that it is */
/* logically fallacious. A via can be declared to be multiple */
/* types, and there is no way to know which type continues the */
/* route without it being explicitly stated. Nevertheless, that */
/* is the way it's implemented. . . */
if ((orient == GEO_CENTER) && (rtype != TT_SPACE) && (r2type != TT_SPACE))
defdata->type = r2type;
else if (orient == GEO_CENTER)
defdata->type = TT_SPACE;
else
defdata->type = ttype;
defdata->x = x2;
defdata->y = y2;
defdata->extlen = extlen;
defdata->tile = tile;
defdata->orient = orient;
return 0; /* Keep going */
}
/*
*------------------------------------------------------------
*
* defCountVias --
*
* First-pass function to count the number of different
* vias used, and retain this information for the netlist
* output.
*
* Results:
* The total number of via definitions to be written.
*
* Side Effects:
* None.
*
*------------------------------------------------------------
*/
int
defCountVias(rootDef, MagicToLefTable, oscale)
CellDef *rootDef;
LefMapping *MagicToLefTable;
float oscale;
{
TileTypeBitMask contactMask, *rmask;
TileType ttype, stype;
int pNum;
CViaData cviadata;
int defCountViaFunc();
cviadata.scale = oscale;
cviadata.total = 0;
cviadata.MagicToLefTbl = MagicToLefTable;
for (pNum = PL_SELECTBASE; pNum < DBNumPlanes; pNum++)
{
cviadata.plane = pNum;
/* Only search for contacts that are on their *home* plane */
TTMaskZero(&contactMask);
for (ttype = TT_TECHDEPBASE; ttype < DBNumUserLayers; ttype++)
if (DBIsContact(ttype) && TTMaskHasType(&DBPlaneTypes[pNum], ttype))
TTMaskSetType(&contactMask, ttype);
/* Also search all stacked types whose residue contact types */
/* are in the mask just generated. */
for (ttype = DBNumUserLayers; ttype < DBNumTypes; ttype++)
{
if (!DBIsContact(ttype)) continue;
rmask = DBResidueMask(ttype);
for (stype = TT_TECHDEPBASE; stype < DBNumUserLayers; stype++)
if (TTMaskHasType(rmask, stype))
{
TTMaskSetType(&contactMask, ttype);
break;
}
}
cviadata.mask = &contactMask;
DBSrPaintArea((Tile *)NULL, rootDef->cd_planes[pNum],
&TiPlaneRect, &contactMask,
defCountViaFunc, (ClientData)&cviadata);
}
return cviadata.total;
}
/* Callback function used by defCountVias */
int
defCountViaFunc(tile, cviadata)
Tile *tile;
CViaData *cviadata;
{
TileType ttype = TiGetType(tile), ctype, rtype;
TileTypeBitMask *rmask, *rmask2;
Tile *tp;
char *lname, vname[100], *vp;
Rect r, r2;
int w, h, offx, offy;
float oscale = cviadata->scale;
lefLayer *lefl;
HashEntry *he;
LefMapping *MagicToLefTable = cviadata->MagicToLefTbl;
/* Techfiles are allowed not to declare a LEF entry, in which */
/* case we would need to initialize the hash table. */
if (LefInfo.ht_table == (HashEntry **) NULL) LefTechInit();
/* Find the canonical type */
if (ttype >= DBNumUserLayers)
{
rmask = DBResidueMask(ttype);
for (ctype = TT_TECHDEPBASE; ctype < DBNumUserLayers; ctype++)
if (TTMaskHasType(rmask, ctype))
break;
if (ctype == DBNumUserLayers)
return 1; /* Error condition */
}
else
{
rmask = NULL;
ctype = ttype;
}
/* Generate a via name from the layer name and tile size */
lname = MagicToLefTable[ctype].lefName;
TiToRect(tile, &r);
/* Boundary search. WARNING: This code is quite naive. The */
/* assumption is that all contacts are rectangular, and therefore */
/* any contact area consisting of multiple tiles must be an amalgam */
/* of regular and/or stacked types. This whole thing should be */
/* replaced by calls to generate layers via the CIF/Calma code. */
/* Top */
for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp = BL(tp))
{
rtype = TiGetBottomType(tp);
if (rtype == ctype)
{
if (!rmask) return 0; /* ignore tile but continue search */
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (rtype >= DBNumUserLayers)
{
rmask2 = DBResidueMask(rtype);
if (TTMaskHasType(rmask2, ctype))
return 0;
}
}
/* Left */
for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp = RT(tp))
{
rtype = TiGetRightType(tp);
if (rtype == ctype)
{
if (!rmask) return 0; /* ignore tile but continue search */
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (rtype >= DBNumUserLayers)
{
rmask2 = DBResidueMask(rtype);
if (TTMaskHasType(rmask2, ctype))
return 0;
}
}
/* Bottom */
for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp = TR(tp))
{
rtype = TiGetTopType(tp);
if (rtype == ctype)
{
if (!rmask) return 0; /* ignore tile but continue search */
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (rtype >= DBNumUserLayers)
{
rmask2 = DBResidueMask(rtype);
if (TTMaskHasType(rmask2, ctype))
return 0;
}
}
/* Right */
for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp = LB(tp))
{
rtype = TiGetLeftType(tp);
if (rtype == ctype)
{
if (!rmask) return 0; /* ignore tile but continue search */
TiToRect(tp, &r2);
GeoInclude(&r2, &r);
}
else if (rtype >= DBNumUserLayers)
{
rmask2 = DBResidueMask(rtype);
if (TTMaskHasType(rmask2, ctype))
return 0;
}
}
/* All values for the via rect are in 1/2 lambda to account */
/* for a centerpoint not on the internal grid. */
r.r_xbot <<= 1;
r.r_xtop <<= 1;
r.r_ybot <<= 1;
r.r_ytop <<= 1;
w = r.r_xtop - r.r_xbot;
h = r.r_ytop - r.r_ybot;
offx = (w >> 1);
offy = (h >> 1);
/* Center the via area on the origin */
r.r_xbot = -offx;
r.r_ybot = -offy;
r.r_xtop = -offx + w;
r.r_ytop = -offy + h;
sprintf(vname, "%s_%.10g_%.10g", lname,
((float)offx * oscale), ((float)offy * oscale));
he = HashFind(&LefInfo, vname);
lefl = (lefLayer *)HashGetValue(he);
if (lefl == NULL)
{
cviadata->total++; /* Increment the count of uses */
lefl = (lefLayer *)mallocMagic(sizeof(lefLayer));
lefl->type = ttype;
lefl->obsType = -1;
lefl->lefClass = CLASS_VIA;
lefl->info.via.area = r;
lefl->info.via.cell = (CellDef *)NULL;
lefl->info.via.lr = (linkedRect *)NULL;
lefl->refCnt = 0; /* These entries will be removed after writing */
HashSetValue(he, lefl);
lefl->canonName = (char *)he->h_key.h_name;
}
return 0; /* Keep the search going */
}
/*
*------------------------------------------------------------
*
* defGetType --
*
* Retrieve the LEF/DEF name of a magic layer from the
* LefInfo hash table.
*
* Results:
* The "official" LEF/DEF layer name of the magic type.
*
* Side Effects:
* If "lefptr" is non-NULL, it is filled with a pointer
* to the appropriate lefLayer entry, or NULL if there
* is no corresponding entry.
*------------------------------------------------------------
*/
char *
defGetType(ttype, lefptr)
TileType ttype;
lefLayer **lefptr;
{
HashSearch hs;
HashEntry *he;
lefLayer *lefl;
int contact = DBIsContact(ttype) ? CLASS_VIA : CLASS_ROUTE;
/* Pick up information from the original LefInfo hash table */
/* entries created during read-in of the tech file. */
if (LefInfo.ht_table != (HashEntry **) NULL)
{
HashStartSearch(&hs);
while (he = HashNext(&LefInfo, &hs))
{
lefl = (lefLayer *)HashGetValue(he);
if (lefl && (lefl->type == ttype) && (contact == lefl->lefClass))
{
if (lefptr) *lefptr = lefl;
return lefl->canonName;
}
}
}
/* If we got here, there is no entry; use the database name */
if (lefptr) *lefptr = (lefLayer *)NULL;
return DBTypeLongNameTbl[ttype];
}
/*
*------------------------------------------------------------
*
* defWriteVias --
*
* Output the VIAS section of a DEF file. We equate magic
* contact areas with DEF "VIAS". A separate via entry is
* generated for each unique geometry. The exact output
* is determined from the CIF output rules.
*
* Results:
* None.
*
* Side Effects:
* Output written to the DEF output file.
*
*------------------------------------------------------------
*/
void
defWriteVias(f, rootDef, oscale, lefMagicToLefLayer)
FILE *f; /* File to write to */
CellDef *rootDef; /* Cell definition to use */
float oscale; /* Output scale factor */
LefMapping *lefMagicToLefLayer;
{
HashSearch hs;
HashEntry *he;
lefLayer *lefl;
TileTypeBitMask *rMask;
TileType ttype;
/* Pick up information from the LefInfo hash table */
/* created by fucntion defCountVias() */
if (LefInfo.ht_table != (HashEntry **) NULL)
{
HashStartSearch(&hs);
while (he = HashNext(&LefInfo, &hs))
{
int size, sep, border;
char *us1, *us2;
lefl = (lefLayer *)HashGetValue(he);
if (!lefl) continue;
/* Only count the generated vias of the type name_sizex_sizey */
if ((us1 = strchr(lefl->canonName, '_')) == NULL ||
(us2 = strrchr(lefl->canonName, '_')) == us1)
continue;
if (lefl->lefClass == CLASS_VIA)
{
fprintf(f, " - %s", (char *)lefl->canonName);
/* Generate squares for the area as determined */
/* by the cifoutput section of the tech file */
rMask = DBResidueMask(lefl->type);
for (ttype = TT_TECHDEPBASE; ttype < DBNumUserLayers; ttype++)
if (TTMaskHasType(rMask, ttype))
fprintf(f, "\n + RECT %s ( %.10g %.10g ) ( %.10g %.10g )",
lefMagicToLefLayer[ttype].lefName,
(float)(lefl->info.via.area.r_xbot) * oscale / 2,
(float)(lefl->info.via.area.r_ybot) * oscale / 2,
(float)(lefl->info.via.area.r_xtop) * oscale / 2,
(float)(lefl->info.via.area.r_ytop) * oscale / 2);
/* Handle the contact cuts. */
if (CIFGetContactSize(lefl->type, &size, &sep, &border))
{
int i, j, nAc, nUp, pitch, left;
Rect square, *r = &lefl->info.via.area;
pitch = size + sep;
nAc = (r->r_xtop - r->r_xbot + sep - (2 * border)) / pitch;
if (nAc == 0)
{
left = (r->r_xbot + r->r_xtop - size) / 2;
if (left >= r->r_xbot) nAc = 1;
}
else
left = (r->r_xbot + r->r_xtop + sep - (nAc * pitch)) / 2;
nUp = (r->r_ytop - r->r_ybot + sep - (2 * border)) / pitch;
if (nUp == 0)
{
square.r_ybot = (r->r_ybot + r->r_ytop - size) / 2;
if (square.r_ybot >= r->r_ybot) nUp = 1;
}
else
square.r_ybot = (r->r_ybot + r->r_ytop + sep - (nUp * pitch)) / 2;
for (i = 0; i < nUp; i++)
{
square.r_ytop = square.r_ybot + size;
square.r_xbot = left;
for (j = 0; j < nAc; j++)
{
square.r_xtop = square.r_xbot + size;
fprintf(f, "\n + RECT %s ( %.10g %.10g )"
" ( %.10g %.10g )",
lefMagicToLefLayer[lefl->type].lefName,
(float)(square.r_xbot) * oscale / 2,
(float)(square.r_ybot) * oscale / 2,
(float)(square.r_xtop) * oscale / 2,
(float)(square.r_ytop) * oscale / 2);
square.r_xbot += pitch;
}
square.r_ybot += pitch;
}
}
else
/* If we can't find the CIF/GDS parameters for cut */
/* generation, then output a single rectangle the */
/* size of the contact tile. */
{
fprintf(f, "\n + RECT %s ( %.10g %.10g ) ( %.10g %.10g )",
lefMagicToLefLayer[lefl->type].lefName,
(float)(lefl->info.via.area.r_xbot) * oscale / 2,
(float)(lefl->info.via.area.r_ybot) * oscale / 2,
(float)(lefl->info.via.area.r_xtop) * oscale / 2,
(float)(lefl->info.via.area.r_ytop) * oscale / 2);
}
fprintf(f, " ;\n");
}
}
}
}
/*
*------------------------------------------------------------
*
* defCountComponents --
*
* First-pass function to count the number of cell
* uses (components) to be written to the DEF output
* file.
*
* Results:
* The total number of uses to be written.
*
* Side Effects:
* None.
*
*------------------------------------------------------------
*/
int
defCountComponents(rootDef)
CellDef *rootDef;
{
pointertype total;
int defCountCompFunc();
TxPrintf("Diagnostic: Finding all components of cell %s\n", rootDef->cd_name);
total = 0;
DBCellEnum(rootDef, defCountCompFunc, (ClientData)&total);
return (int)total;
}
/* Callback function used by defCountComponents */
int
defCountCompFunc(cellUse, total)
CellUse *cellUse;
pointertype *total;
{
/* Ignore any cellUse that does not have an identifier string. */
if (cellUse->cu_id == NULL) return 0;
(*total)++; /* Increment the count of uses */
return 0; /* Keep the search going */
}
/*
*------------------------------------------------------------
*
* defWriteComponents --
*
* Output the COMPONENTS section of the DEF file. This
* is a listing of all cell uses, their placement, and
* orientation.
*
* Results:
* None.
*
* Side Effects:
* Output to the DEF file.
*
*------------------------------------------------------------
*/
void
defWriteComponents(f, rootDef, oscale)
FILE *f; /* File to write to */
CellDef *rootDef; /* Cell definition to use */
float oscale; /* Output scale factor */
{
DefData defdata;
int defComponentFunc(); /* Forward declaration */
defdata.f = f;
defdata.scale = oscale;
DBCellEnum(rootDef, defComponentFunc, (ClientData)&defdata);
}
/* Callback function used by defWriteComponents */
int
defComponentFunc(cellUse, defdata)
CellUse *cellUse;
DefData *defdata;
{
FILE *f = defdata->f;
float oscale = defdata->scale;
/* Ignore any cellUse that does not have an identifier string. */
if (cellUse->cu_id == NULL) return 0;
fprintf(f, " - %s %s\n + PLACED ( %.10g %.10g ) %s ;\n",
cellUse->cu_id, cellUse->cu_def->cd_name,
(float)cellUse->cu_bbox.r_xbot * oscale,
(float)cellUse->cu_bbox.r_ybot * oscale,
defTransPos(&cellUse->cu_transform));
return 0; /* Keep the search going */
}
/*
*------------------------------------------------------------
*
* defMakeInverseLayerMap ---
*
* Generate an array of pointers to lefLayer structures for each
* magic type so we can do a quick lookup when searching over tiles.
*
* Results:
* Pointer to the inverse layer map.
*
* Side effects:
* Memory is allocated for the map structure array.
*
*------------------------------------------------------------
*/
LefMapping *
defMakeInverseLayerMap()
{
LefMapping *lefMagicToLefLayer;
lefLayer *lefl;
TileType i;
char *lefname;
lefMagicToLefLayer = (LefMapping *)mallocMagic(DBNumUserLayers
* sizeof(LefMapping));
for (i = TT_TECHDEPBASE; i < DBNumUserLayers; i++)
{
lefname = defGetType(i, &lefl);
lefMagicToLefLayer[i].lefName = lefname;
lefMagicToLefLayer[i].lefInfo = lefl;
}
return lefMagicToLefLayer;
}
/*
*------------------------------------------------------------
*
* DefWriteAll --
*
* Results:
*
* Side Effects:
*
*------------------------------------------------------------
*/
/* To do: routine DefWriteAll(). */
/* DEF does not handle hierarchy. However, we should assume that we */
/* want to write out a DEF file for each cell in the hierarchy. But, */
/* we should stop at any cells defining ports, assuming that they are */
/* standard cells and not part of the routing. */
/* Maybe there should be a method for specifying that any hierarchy */
/* should be flattened when writing to the DEF file output. */
/*
*------------------------------------------------------------
*
* DefWriteCell --
*
* Write DEF-format output for the indicated cell.
*
* Results:
* None.
*
* Side effects:
* Writes a single .def file to disk.
*
*------------------------------------------------------------
*/
void
DefWriteCell(def, outName, allSpecial)
CellDef *def; /* Cell being written */
char *outName; /* Name of output file, or NULL. */
bool allSpecial; /* Treat all nets as SPECIALNETS? */
{
char *filename;
FILE *f;
NetCount nets;
int total;
float scale = CIFGetOutputScale(1); /* Note that "1" here corresponds
* to "1000" in the header UNITS line
*/
LefMapping *lefMagicToLefLayer;
int i;
lefLayer *lefl;
HashEntry *he;
f = lefFileOpen(def, outName, ".def", "w", &filename);
TxPrintf("Generating DEF output %s for cell %s:\n", filename, def->cd_name);
if (f == NULL)
{
#ifdef MAGIC_WRAPPER
TxError("Cannot open output file %s (%s).\n", filename,
strerror(errno));
#else
TxError("Cannot open output file: ");
perror(filename);
#endif
return;
}
defWriteHeader(def, f, scale);
lefMagicToLefLayer = defMakeInverseLayerMap();
/* Vias---magic contact areas are reported as vias. */
total = defCountVias(def, lefMagicToLefLayer, scale);
fprintf(f, "VIAS %d ;\n", total);
if (total > 0)
defWriteVias(f, def, scale, lefMagicToLefLayer);
fprintf(f, "END VIAS\n\n");
/* Components (i.e., cell uses) */
total = defCountComponents(def);
fprintf(f, "COMPONENTS %d ;\n", total);
if (total > 0)
defWriteComponents(f, def, scale);
fprintf(f, "END COMPONENTS\n\n");
/* Pins---assume no pins (for now) */
fprintf(f, "PINS 0 ;\nEND PINS\n\n");
/* Count the number of nets and "special" nets */
nets = defCountNets(def, allSpecial);
/* "Special" nets---nets matching $GND, $VDD, or $globals(*) */
fprintf(f, "SPECIALNETS %d ;\n", nets.special);
if (nets.special > 0)
defWriteNets(f, def, scale, lefMagicToLefLayer, (allSpecial) ?
ALL_SPECIAL : DO_SPECIAL);
fprintf(f, "END SPECIALNETS\n\n");
/* "Regular" nets */
fprintf(f, "NETS %d ;\n", nets.regular);
if (nets.regular > 0)
defWriteNets(f, def, scale, lefMagicToLefLayer, DO_REGULAR);
fprintf(f, "END NETS\n\n");
if (nets.has_nets) {
EFFlatDone();
EFDone();
}
fprintf(f, "END DESIGN\n\n");
fclose(f);
freeMagic((char *)lefMagicToLefLayer);
lefRemoveGeneratedVias();
}
|