Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 3242 lines (3026 sloc) 120.643 kb
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 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
// Taken from GDC source tree. Original by David Friedman.
// Released under the Artistic License found in dmd/artistic.txt

#include "id.h"
#if defined(_MSC_VER)
#include <ctype.h>
#endif

namespace AsmParserx8664
{

    typedef enum
    {
        Reg_Invalid = -1,
        Reg_EAX = 0,
        Reg_EBX,
        Reg_ECX,
        Reg_EDX,
        Reg_ESI,
        Reg_EDI,
        Reg_EBP,
        Reg_ESP,
        Reg_ST,
        Reg_ST1, Reg_ST2, Reg_ST3, Reg_ST4, Reg_ST5, Reg_ST6, Reg_ST7,
        Reg_MM0, Reg_MM1, Reg_MM2, Reg_MM3, Reg_MM4, Reg_MM5, Reg_MM6, Reg_MM7,
        Reg_XMM0, Reg_XMM1, Reg_XMM2, Reg_XMM3, Reg_XMM4, Reg_XMM5, Reg_XMM6, Reg_XMM7,

        Reg_RAX, Reg_RBX, Reg_RCX, Reg_RDX, Reg_RSI, Reg_RDI, Reg_RBP, Reg_RSP,
        Reg_R8, Reg_R9, Reg_R10, Reg_R11, Reg_R12, Reg_R13, Reg_R14, Reg_R15,
        Reg_R8B, Reg_R9B, Reg_R10B, Reg_R11B, Reg_R12B, Reg_R13B, Reg_R14B, Reg_R15B,
        Reg_R8W, Reg_R9W, Reg_R10W, Reg_R11W, Reg_R12W, Reg_R13W, Reg_R14W, Reg_R15W,
        Reg_R8D, Reg_R9D, Reg_R10D, Reg_R11D, Reg_R12D, Reg_R13D, Reg_R14D, Reg_R15D,
        Reg_XMM8, Reg_XMM9, Reg_XMM10, Reg_XMM11, Reg_XMM12, Reg_XMM13, Reg_XMM14, Reg_XMM15,
        Reg_RIP,
        Reg_SIL, Reg_DIL, Reg_BPL, Reg_SPL,

        Reg_EFLAGS,
        Reg_CS,
        Reg_DS,
        Reg_SS,
        Reg_ES,
        Reg_FS,
        Reg_GS,
        Reg_AX, Reg_BX, Reg_CX, Reg_DX, Reg_SI, Reg_DI, Reg_BP, Reg_SP,
        Reg_AL, Reg_AH, Reg_BL, Reg_BH, Reg_CL, Reg_CH, Reg_DL, Reg_DH,
        Reg_CR0, Reg_CR2, Reg_CR3, Reg_CR4,
        Reg_DR0, Reg_DR1, Reg_DR2, Reg_DR3, Reg_DR6, Reg_DR7,
        Reg_TR3, Reg_TR4, Reg_TR5, Reg_TR6, Reg_TR7
    } Reg;

    static const int N_Regs = /*gp*/ 8 + /*fp*/ 8 + /*mmx*/ 8 + /*sse*/ 8 +
                                     /*seg*/ 6 + /*16bit*/ 8 + /*8bit*/ 8 + /*sys*/ 4+6+5 + /*flags*/ + 1
                                     + 8 /*RAX, etc*/
                                     + 8 /*R8-15*/
                                     + 4 /*SIL, etc. 8-bit*/
                                     + 8 /*R8-15B*/
                                     + 8 /*R8-15W*/
                                     + 8 /*R8-15D*/
                                     + 8 /*XMM8-15*/
                                     + 1 /*RIP*/

                                     ;

#define NULL_TREE ""

    static struct
    {
        const char * name;
        std::string gccName; // GAS will take upper case, but GCC won't (needed for the clobber list)
        Identifier * ident;
        char size;
        char baseReg; // %% todo: Reg, Reg_XX
    } regInfo[N_Regs] =
    {
        { "EAX", NULL_TREE, NULL, 4, Reg_EAX },
        { "EBX", NULL_TREE, NULL, 4, Reg_EBX },
        { "ECX", NULL_TREE, NULL, 4, Reg_ECX },
        { "EDX", NULL_TREE, NULL, 4, Reg_EDX },
        { "ESI", NULL_TREE, NULL, 4, Reg_ESI },
        { "EDI", NULL_TREE, NULL, 4, Reg_EDI },
        { "EBP", NULL_TREE, NULL, 4, Reg_EBP },
        { "ESP", NULL_TREE, NULL, 4, Reg_ESP },
        { "ST", NULL_TREE, NULL, 10, Reg_ST },
        { "ST(1)", NULL_TREE, NULL,10, Reg_ST1 },
        { "ST(2)", NULL_TREE, NULL,10, Reg_ST2 },
        { "ST(3)", NULL_TREE, NULL,10, Reg_ST3 },
        { "ST(4)", NULL_TREE, NULL,10, Reg_ST4 },
        { "ST(5)", NULL_TREE, NULL,10, Reg_ST5 },
        { "ST(6)", NULL_TREE, NULL,10, Reg_ST6 },
        { "ST(7)", NULL_TREE, NULL,10, Reg_ST7 },
        { "MM0", NULL_TREE, NULL, 8, Reg_MM0 },
        { "MM1", NULL_TREE, NULL, 8, Reg_MM1 },
        { "MM2", NULL_TREE, NULL, 8, Reg_MM2 },
        { "MM3", NULL_TREE, NULL, 8, Reg_MM3 },
        { "MM4", NULL_TREE, NULL, 8, Reg_MM4 },
        { "MM5", NULL_TREE, NULL, 8, Reg_MM5 },
        { "MM6", NULL_TREE, NULL, 8, Reg_MM6 },
        { "MM7", NULL_TREE, NULL, 8, Reg_MM7 },
        { "XMM0", NULL_TREE, NULL, 16, Reg_XMM0 },
        { "XMM1", NULL_TREE, NULL, 16, Reg_XMM1 },
        { "XMM2", NULL_TREE, NULL, 16, Reg_XMM2 },
        { "XMM3", NULL_TREE, NULL, 16, Reg_XMM3 },
        { "XMM4", NULL_TREE, NULL, 16, Reg_XMM4 },
        { "XMM5", NULL_TREE, NULL, 16, Reg_XMM5 },
        { "XMM6", NULL_TREE, NULL, 16, Reg_XMM6 },
        { "XMM7", NULL_TREE, NULL, 16, Reg_XMM7 },

        { "RAX", NULL_TREE, NULL, 8, Reg_RAX },
        { "RBX", NULL_TREE, NULL, 8, Reg_RBX },
        { "RCX", NULL_TREE, NULL, 8, Reg_RCX },
        { "RDX", NULL_TREE, NULL, 8, Reg_RDX },
        { "RSI", NULL_TREE, NULL, 8, Reg_RSI },
        { "RDI", NULL_TREE, NULL, 8, Reg_RDI },
        { "RBP", NULL_TREE, NULL, 8, Reg_RBP },
        { "RSP", NULL_TREE, NULL, 8, Reg_RSP },
        { "R8", NULL_TREE, NULL, 8, Reg_R8 },
        { "R9", NULL_TREE, NULL, 8, Reg_R9 },
        { "R10", NULL_TREE, NULL, 8, Reg_R10 },
        { "R11", NULL_TREE, NULL, 8, Reg_R11 },
        { "R12", NULL_TREE, NULL, 8, Reg_R12 },
        { "R13", NULL_TREE, NULL, 8, Reg_R13 },
        { "R14", NULL_TREE, NULL, 8, Reg_R14 },
        { "R15", NULL_TREE, NULL, 8, Reg_R15 },
        { "R8B", NULL_TREE, NULL, 1, Reg_R8 },
        { "R9B", NULL_TREE, NULL, 1, Reg_R9 },
        { "R10B", NULL_TREE, NULL, 1, Reg_R10 },
        { "R11B", NULL_TREE, NULL, 1, Reg_R11 },
        { "R12B", NULL_TREE, NULL, 1, Reg_R12 },
        { "R13B", NULL_TREE, NULL, 1, Reg_R13 },
        { "R14B", NULL_TREE, NULL, 1, Reg_R14 },
        { "R15B", NULL_TREE, NULL, 1, Reg_R15 },
        { "R8W", NULL_TREE, NULL, 2, Reg_R8 },
        { "R9W", NULL_TREE, NULL, 2, Reg_R9 },
        { "R10W", NULL_TREE, NULL, 2, Reg_R10 },
        { "R11W", NULL_TREE, NULL, 2, Reg_R11 },
        { "R12W", NULL_TREE, NULL, 2, Reg_R12 },
        { "R13W", NULL_TREE, NULL, 2, Reg_R13 },
        { "R14W", NULL_TREE, NULL, 2, Reg_R14 },
        { "R15W", NULL_TREE, NULL, 2, Reg_R15 },
        { "R8D", NULL_TREE, NULL, 4, Reg_R8 },
        { "R9D", NULL_TREE, NULL, 4, Reg_R9 },
        { "R10D", NULL_TREE, NULL, 4, Reg_R10 },
        { "R11D", NULL_TREE, NULL, 4, Reg_R11 },
        { "R12D", NULL_TREE, NULL, 4, Reg_R12 },
        { "R13D", NULL_TREE, NULL, 4, Reg_R13 },
        { "R14D", NULL_TREE, NULL, 4, Reg_R14 },
        { "R15D", NULL_TREE, NULL, 4, Reg_R15 },
        { "XMM8", NULL_TREE, NULL, 16, Reg_XMM8 },
        { "XMM9", NULL_TREE, NULL, 16, Reg_XMM9 },
        { "XMM10", NULL_TREE, NULL, 16, Reg_XMM10 },
        { "XMM11", NULL_TREE, NULL, 16, Reg_XMM11 },
        { "XMM12", NULL_TREE, NULL, 16, Reg_XMM12 },
        { "XMM13", NULL_TREE, NULL, 16, Reg_XMM13 },
        { "XMM14", NULL_TREE, NULL, 16, Reg_XMM14 },
        { "XMM15", NULL_TREE, NULL, 16, Reg_XMM15 },
        { "RIP", NULL_TREE, NULL, 8, Reg_RIP },
        { "SIL", NULL_TREE, NULL, 1, Reg_SIL },
        { "DIL", NULL_TREE, NULL, 1, Reg_DIL },
        { "BPL", NULL_TREE, NULL, 1, Reg_BPL },
        { "SPL", NULL_TREE, NULL, 1, Reg_SPL },

        { "FLAGS", NULL_TREE, NULL, 0, Reg_EFLAGS }, // the gcc name is "flags"; not used in assembler input
        { "CS", NULL_TREE, NULL, 2, -1 },
        { "DS", NULL_TREE, NULL, 2, -1 },
        { "SS", NULL_TREE, NULL, 2, -1 },
        { "ES", NULL_TREE, NULL, 2, -1 },
        { "FS", NULL_TREE, NULL, 2, -1 },
        { "GS", NULL_TREE, NULL, 2, -1 },
        { "AX", NULL_TREE, NULL, 2, Reg_EAX },
        { "BX", NULL_TREE, NULL, 2, Reg_EBX },
        { "CX", NULL_TREE, NULL, 2, Reg_ECX },
        { "DX", NULL_TREE, NULL, 2, Reg_EDX },
        { "SI", NULL_TREE, NULL, 2, Reg_ESI },
        { "DI", NULL_TREE, NULL, 2, Reg_EDI },
        { "BP", NULL_TREE, NULL, 2, Reg_EBP },
        { "SP", NULL_TREE, NULL, 2, Reg_ESP },
        { "AL", NULL_TREE, NULL, 1, Reg_EAX },
        { "AH", NULL_TREE, NULL, 1, Reg_EAX },
        { "BL", NULL_TREE, NULL, 1, Reg_EBX },
        { "BH", NULL_TREE, NULL, 1, Reg_EBX },
        { "CL", NULL_TREE, NULL, 1, Reg_ECX },
        { "CH", NULL_TREE, NULL, 1, Reg_ECX },
        { "DL", NULL_TREE, NULL, 1, Reg_EDX },
        { "DH", NULL_TREE, NULL, 1, Reg_EDX },
        { "CR0", NULL_TREE, NULL, 0, -1 },
        { "CR2", NULL_TREE, NULL, 0, -1 },
        { "CR3", NULL_TREE, NULL, 0, -1 },
        { "CR4", NULL_TREE, NULL, 0, -1 },
        { "DR0", NULL_TREE, NULL, 0, -1 },
        { "DR1", NULL_TREE, NULL, 0, -1 },
        { "DR2", NULL_TREE, NULL, 0, -1 },
        { "DR3", NULL_TREE, NULL, 0, -1 },
        { "DR6", NULL_TREE, NULL, 0, -1 },
        { "DR7", NULL_TREE, NULL, 0, -1 },
        { "TR3", NULL_TREE, NULL, 0, -1 },
        { "TR4", NULL_TREE, NULL, 0, -1 },
        { "TR5", NULL_TREE, NULL, 0, -1 },
        { "TR6", NULL_TREE, NULL, 0, -1 },
        { "TR7", NULL_TREE, NULL, 0, -1 }
    };

    typedef enum
    {
        No_Type_Needed,
        Int_Types,
        Word_Types, // same as Int_Types, but byte is not allowed
        FP_Types,
        FPInt_Types,
        Byte_NoType, // byte only, but no type suffix
    } TypeNeeded;

    typedef enum
    {
        No_Link,
        Out_Mnemonic,
        Next_Form
    } OpLink;

    typedef enum
    {
        Clb_SizeAX = 0x01,
        Clb_SizeDXAX = 0x02,
        Clb_EAX = 0x03,
        Clb_DXAX_Mask = 0x103,
        Clb_SizeRDXRAX = 0x100,

        Clb_Flags = 0x04,
        Clb_DI = 0x08,
        Clb_SI = 0x10,
        Clb_CX = 0x20,
        Clb_ST = 0x40,
        Clb_SP = 0x80 // Doesn't actually let GCC know the frame pointer is modified
    } ImplicitClober;

// "^ +/..\([A-Za-z_0-9]+\).*" -> " \1,"
    typedef enum
    {
        Op_Invalid,
        Op_Adjust,
        Op_Dst,
        Op_Upd,
        Op_DstW,
        Op_DstF,
        Op_UpdF,
        Op_DstSrc,
        Op_DstSrcF,
        Op_UpdSrcF,
        Op_DstSrcFW,
        Op_UpdSrcFW,
        Op_DstSrcSSE,
        Op_DstSrcMMX,
        Op_DstSrcImmS,
        Op_DstSrcImmM,
        Op_UpdSrcShft,
        Op_DstSrcNT,
        Op_UpdSrcNT,
        Op_DstMemNT,
        Op_DstRMBNT,
        Op_DstRMWNT,
        Op_UpdUpd,
        Op_UpdUpdF,
        Op_Src,
        Op_SrcRMWNT,
        Op_SrcW,
        Op_SrcImm,
        Op_Src_DXAXF,
        Op_SrcMemNT,
        Op_SrcMemNTF,
        Op_SrcSrc,
        Op_SrcSrcF,
        Op_SrcSrcFW,
        Op_SrcSrcSSEF,
        Op_SrcSrcMMX,
        Op_Shift,
        Op_Branch,
        Op_CBranch,
        Op_0,
        Op_0_AX,
        Op_0_DXAX,
        Op_Loop,
        Op_Flags,
        Op_F0_ST,
        Op_F0_P,
        Op_Fs_P,
        Op_Fis,
        Op_Fis_ST,
        Op_Fis_P,
        Op_Fid,
        Op_Fid_P,
        Op_FidR_P,
        Op_Ffd,
        Op_FfdR,
        Op_Ffd_P,
        Op_FfdR_P,
        Op_FfdRR_P,
        Op_Fd_P,
        Op_FdST,
        Op_FMath,
        Op_FMath0,
        Op_FMath2,
        Op_FdSTiSTi,
        Op_FdST0ST1,
        Op_FPMath,
        Op_FCmp,
        Op_FCmp1,
        Op_FCmpP,
        Op_FCmpP1,
        Op_FCmpFlg,
        Op_FCmpFlgP,
        Op_fld,
        Op_fldR,
        Op_fxch,
        Op_fxch1,
        Op_fxch0,
        Op_SizedStack,
        Op_bound,
        Op_bswap,
        Op_cmps,
        Op_cmpsd,
        Op_cmpsX,
        Op_cmpxchg,
        Op_cmpxchg16b,
        Op_cmpxchg8b,
        Op_cpuid,
        Op_enter,
        Op_fdisi,
        Op_feni,
        Op_fsetpm,
        Op_fXstsw,
        Op_imul,
        Op_imul2,
        Op_imul1,
        Op_in,
        Op_ins,
        Op_insX,
        Op_iret,
        Op_iretd,
        Op_iretq,
        Op_lods,
        Op_lodsX,
        Op_movs,
        Op_movsd,
        Op_movsX,
        Op_movsx,
        Op_movzx,
        Op_mul,
        Op_out,
        Op_outs,
        Op_outsX,
        Op_push,
        Op_ret,
        Op_retf,
        Op_scas,
        Op_scasX,
        Op_stos,
        Op_stosX,
        Op_xgetbv,
        Op_xlat,
        N_AsmOpInfo,
        Op_Align,
        Op_Even,
        Op_Naked,
        Op_db,
        Op_ds,
        Op_di,
        Op_dl,
        Op_df,
        Op_dd,
        Op_de
    } AsmOp;

    typedef enum
    {
        Opr_None = 0,
        OprC_MRI = 1,
        OprC_MR = 2,
        OprC_Mem = 3,
        OprC_Reg = 4,
        OprC_Imm = 5,
        OprC_SSE = 6,
        OprC_SSE_Mem = 7,
        OprC_R32 = 8,
        OprC_RWord = 9,
        OprC_RFP = 10,
        OprC_AbsRel = 11,
        OprC_Relative = 12,
        OprC_Port = 13, // DX or imm
        OprC_AX = 14, // AL,AX,EAX
        OprC_DX = 15, // only DX
        OprC_MMX = 16,
        OprC_MMX_Mem = 17,
        OprC_Shift = 18, // imm or CL

        Opr_ClassMask = 0x1f,

        Opr_Dest = 0x20,
        Opr_Update = 0x60,

        Opr_NoType = 0x80,
    } OprVals;


    typedef struct
    {
    } AsmOprInfo;

    typedef unsigned char Opr;

    typedef struct
    {
        Opr operands[3];
        unsigned char
    needsType : 3,
    implicitClobbers : 8,
    linkType : 2;
        unsigned link;

        /*
bool takesLabel() {
return operands[0] & Opr_Label;
}
*/

        unsigned nOperands()
        {
            if ( !operands[0] )
                return 0;
            else if ( !operands[1] )
                return 1;
            else if ( !operands[2] )
                return 2;
            else
                return 3;
        }
    } AsmOpInfo;

    typedef enum
    {
        Mn_fdisi,
        Mn_feni,
        Mn_fsetpm,
        Mn_iretw,
        Mn_iret,
        Mn_iretq,
        Mn_lret,
        Mn_cmpxchg8b,
        Mn_cmpxchg16b,
        N_AltMn
    } Alternate_Mnemonics;

    static const char * alternateMnemonics[N_AltMn] =
    {
        ".byte 0xdb, 0xe1",
        ".byte 0xdb, 0xe0",
        ".byte 0xdb, 0xe4",
        "iretw",
        "iret",
        "iretq",
        "lret",
        "cmpxchg8b",
        "cmpxchg16b"
   };

#define mri OprC_MRI
#define mr OprC_MR
#define mem OprC_Mem
// for now mfp=mem
#define mfp OprC_Mem
#define reg OprC_Reg
#define imm OprC_Imm
#define sse OprC_SSE
#define ssem OprC_SSE_Mem
#define mmx OprC_MMX
#define mmxm OprC_MMX_Mem
#define r32 OprC_R32
#define rw OprC_RWord
#define rfp OprC_RFP
#define port OprC_Port
#define ax OprC_AX
#define dx OprC_DX
#define shft OprC_Shift
#define D Opr_Dest
#define U Opr_Update
#define N Opr_NoType
//#define L Opr_Label

// D=dest, N=notype
    static AsmOpInfo asmOpInfo[N_AsmOpInfo] =
    {
        /* Op_Invalid */ {},
        /* Op_Adjust */ { 0,0,0, 0, Clb_EAX /*just AX*/ },
        /* Op_Dst */ { D|mr, 0, 0, 1 },
        /* Op_Upd */ { U|mr, 0, 0, 1 },
        /* Op_DstW */ { D|mr, 0, 0, Word_Types },
        /* Op_DstF */ { D|mr, 0, 0, 1, Clb_Flags },
        /* Op_UpdF */ { U|mr, 0, 0, 1, Clb_Flags },
        /* Op_DstSrc */ { D|mr, mri, 0,/**/1 },
        /* Op_DstSrcF */ { D|mr, mri, 0,/**/1, Clb_Flags },
        /* Op_UpdSrcF */ { U|mr, mri, 0,/**/1, Clb_Flags },
        /* Op_DstSrcFW */ { D|mr, mri, 0,/**/Word_Types, Clb_Flags },
        /* Op_UpdSrcFW */ { U|mr, mri, 0,/**/Word_Types, Clb_Flags },
        /* Op_DstSrcSSE */ { U|sse, ssem, 0 }, // some may not be update %%
        /* Op_DstSrcMMX */ { U|mmx, mmxm, 0 }, // some may not be update %%
        /* Op_DstSrcImmS*/ { U|sse, ssem, N|imm }, // some may not be update %%
        /* Op_DstSrcImmM*/ { U|mmx, mmxm, N|imm }, // some may not be update %%
        /* Op_UpdSrcShft*/ { U|mr, reg, N|shft, 1, Clb_Flags }, // 16/32 only
        /* Op_DstSrcNT */ { D|mr, mr, 0, 0 }, // used for movd .. operands can be rm32,sse,mmx
        /* Op_UpdSrcNT */ { U|mr, mr, 0, 0 }, // used for movd .. operands can be rm32,sse,mmx
        /* Op_DstMemNT */ { D|mem, 0, 0 },
        /* Op_DstRMBNT */ { D|mr, 0, 0, Byte_NoType },
        /* Op_DstRMWNT */ { D|mr, 0, 0 },
        /* Op_UpdUpd */ { U|mr,U|mr, 0,/**/1 },
        /* Op_UpdUpdF */ { U|mr,U|mr, 0,/**/1, Clb_Flags },
        /* Op_Src */ { mri, 0, 0, 1 },
        /* Op_SrcRMWNT */ { mr, 0, 0, 0 },
        /* Op_SrcW */ { mri, 0, 0, Word_Types },
        /* Op_SrcImm */ { imm },
        /* Op_Src_DXAXF */ { mr, 0, 0, 1, Clb_SizeDXAX|Clb_Flags },
        /* Op_SrcMemNT */ { mem, 0, 0 },
        /* Op_SrcMemNTF */ { mem, 0, 0, 0, Clb_Flags },
        /* Op_SrcSrc */ { mr, mri, 0, 1 },
        /* Op_SrcSrcF */ { mr, mri, 0, 1, Clb_Flags },
        /* Op_SrcSrcFW */ { mr, mri, 0, Word_Types, Clb_Flags },
        /* Op_SrcSrcSSEF*/ { sse, ssem, 0, 0, Clb_Flags },
        /* Op_SrcSrcMMX */ { mmx, mmx, 0, },
        /* Op_Shift */ { D|mr,N|shft, 0,/**/1, Clb_Flags },
        /* Op_Branch */ { mri },
        /* Op_CBranch */ { imm },
        /* Op_0 */ { 0,0,0 },
        /* Op_0_AX */ { 0,0,0, 0, Clb_SizeAX },
        /* Op_0_DXAX */ { 0,0,0, 0, Clb_SizeDXAX }, // but for cwd/cdq -- how do know the size..
        /* Op_Loop */ { imm, 0, 0, 0, Clb_CX },
        /* Op_Flags */ { 0,0,0, 0, Clb_Flags },
        /* Op_F0_ST */ { 0,0,0, 0, Clb_ST },
        /* Op_F0_P */ { 0,0,0, 0, Clb_ST }, // push, pops, etc. not sure how to inform gcc..
        /* Op_Fs_P */ { mem, 0, 0, 0, Clb_ST }, // "
        /* Op_Fis */ { mem, 0, 0, FPInt_Types }, // only 16bit and 32bit, DMD defaults to 16bit
        /* Op_Fis_ST */ { mem, 0, 0, FPInt_Types, Clb_ST }, // "
        /* Op_Fis_P */ { mem, 0, 0, FPInt_Types, Clb_ST }, // push and pop, fild so also 64 bit
        /* Op_Fid */ { D|mem, 0, 0, FPInt_Types }, // only 16bit and 32bit, DMD defaults to 16bit
        /* Op_Fid_P */ { D|mem, 0, 0, FPInt_Types, Clb_ST, Next_Form, Op_FidR_P }, // push and pop, fild so also 64 bit
        /* Op_FidR_P */ { D|mem,rfp, 0, FPInt_Types, Clb_ST }, // push and pop, fild so also 64 bit
        /* Op_Ffd */ { D|mfp, 0, 0, FP_Types, 0, Next_Form, Op_FfdR }, // only 16bit and 32bit, DMD defaults to 16bit, reg form doesn't need type
        /* Op_FfdR */ { D|rfp, 0, 0 },
        /* Op_Ffd_P */ { D|mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FfdR_P }, // pop, fld so also 80 bit, "
        /* Op_FfdR_P */ { D|rfp, 0, 0, 0, Clb_ST, Next_Form, Op_FfdRR_P },
        /* Op_FfdRR_P */ { D|rfp,rfp, 0, 0, Clb_ST },
        /* Op_Fd_P */ { D|mem, 0, 0, 0, Clb_ST }, // "
        /* Op_FdST */ { D|rfp, 0, 0 },
        /* Op_FMath */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FMath0 }, // and only single or double prec
        /* Op_FMath0 */ { 0, 0, 0, 0, Clb_ST, Next_Form, Op_FMath2 }, // pops
        /* Op_FMath2 */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_FdST0ST1 }, // and only single or double prec
        /* Op_FdSTiSTi */ { D|rfp, rfp, 0, },
        /* Op_FdST0ST1 */ { 0, 0, 0, },
        /* Op_FPMath */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_F0_P }, // pops
        /* Op_FCmp */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmp1 }, // DMD defaults to float ptr
        /* Op_FCmp1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_0 },
        /* Op_FCmpP */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmpP1 }, // pops
        /* Op_FCmpP1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_F0_P }, // pops
        /* Op_FCmpFlg */ { rfp, 0, 0, 0, Clb_Flags },
        /* Op_FCmpFlgP */ { rfp, 0, 0, 0, Clb_Flags }, // pops
        /* Op_fld */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_fldR },
        /* Op_fldR */ { rfp, 0, 0, 0, Clb_ST },
        /* Op_fxch */ { D|rfp,D|rfp, 0, 0, Clb_ST, Next_Form, Op_fxch1 }, // not in intel manual?, but DMD allows it (gas won't), second arg must be ST
        /* Op_fxch1 */ { D|rfp, 0, 0, 0, Clb_ST, Next_Form, Op_fxch0 },
        /* Op_fxch0 */ { 0, 0, 0, 0, Clb_ST }, // Also clobbers ST(1)
        /* Op_SizedStack*/ { 0, 0, 0, 0, Clb_SP }, // type suffix special case
        /* Op_bound */ { mr, mri, 0, Word_Types }, // operands *not* reversed for gas
        /* Op_bswap */ { D|r32 },
        /* Op_cmps */ { mem, mem, 0, 1, Clb_DI|Clb_SI|Clb_Flags },
        /* Op_cmpsd */ { 0, 0, 0, 0, Clb_DI|Clb_SI|Clb_Flags, Next_Form, Op_DstSrcImmS },
        /* Op_cmpsX */ { 0, 0, 0, 0, Clb_DI|Clb_SI|Clb_Flags },
        /* Op_cmpxchg */ { D|mr, reg, 0, 1, Clb_SizeAX|Clb_Flags },
        /* Op_cmpxchg16b */ { D|mem/*128*/,0,0, 0, Clb_SizeRDXRAX/*64*/|Clb_Flags, Out_Mnemonic, Mn_cmpxchg16b },
        /* Op_cmpxchg8b */ { D|mem/*64*/,0,0, 0, Clb_SizeDXAX/*32*/|Clb_Flags, Out_Mnemonic, Mn_cmpxchg8b },
        /* Op_cpuid */ { 0,0,0 }, // Clobbers eax, ebx, ecx, and edx. Handled specially below.
        /* Op_enter */ { imm, imm }, // operands *not* reversed for gas, %% inform gcc of EBP clobber?,
        /* Op_fdisi */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_fdisi },
        /* Op_feni */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_feni },
        /* Op_fsetpm */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_fsetpm },
        /* Op_fXstsw */ { D|mr, 0, 0, }, // ax is the only allowed register
        /* Op_imul */ { D|reg, mr, imm, 1, Clb_Flags, Next_Form, Op_imul2 }, // 16/32 only
        /* Op_imul2 */ { D|reg, mri, 0, 1, Clb_Flags, Next_Form, Op_imul1 }, // 16/32 only
        /* Op_imul1 */ { mr, 0, 0, 1, Clb_Flags|Clb_SizeDXAX },
        /* Op_in */ { D|ax,N|port,0, 1 },
        /* Op_ins */ { mem,N|dx, 0, 1, Clb_DI }, // can't override ES segment for this one
        /* Op_insX */ { 0, 0, 0, 0, Clb_DI }, // output segment overrides %% needs work
        /* Op_iret */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_iretw },
        /* Op_iretd */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_iret },
        /* Op_iretq */ { 0,0,0, 0, 0, Out_Mnemonic, Mn_iretq },
        /* Op_lods */ { mem, 0, 0, 1, Clb_SI },
        /* Op_lodsX */ { 0, 0, 0, 0, Clb_SI },
        /* Op_movs */ { mem, mem, 0, 1, Clb_DI|Clb_SI }, // only src/DS can be overridden
        /* Op_movsd */ { 0, 0, 0, 0, Clb_DI|Clb_SI, Next_Form, Op_DstSrcSSE }, // %% gas doesn't accept movsd .. has to movsl
        /* Op_movsX */ { 0, 0, 0, 0, Clb_DI|Clb_SI },
        /* Op_movsx */ { D|reg, mr, 0, 1 }, // type suffix is special case
        /* Op_movzx */ { D|reg, mr, 0, 1 }, // type suffix is special case
        /* Op_mul */ { U|ax, mr, 0, 1, Clb_SizeDXAX|Clb_Flags, Next_Form, Op_Src_DXAXF },
        /* Op_out */ { N|port,ax, 0, 1 },
        /* Op_outs */ { N|dx, mem, 0, 1, Clb_SI },
        /* Op_outsX */ { 0, 0, 0, 0, Clb_SI },
        /* Op_push */ { mri, 0, 0, 0, Clb_SP }, // would be Op_SrcW, but DMD defaults to 32-bit for immediate form
        /* Op_ret */ { imm, 0, 0, 0, 0, Next_Form, Op_0 },
        /* Op_retf */ { 0, 0, 0, 0, 0, Out_Mnemonic, Mn_lret },
        /* Op_scas */ { mem, 0, 0, 1, Clb_DI|Clb_Flags },
        /* Op_scasX */ { 0, 0, 0, 0, Clb_DI|Clb_Flags },
        /* Op_stos */ { mem, 0, 0, 1, Clb_DI },
        /* Op_stosX */ { 0, 0, 0, 0, Clb_DI },
        /* Op_xgetbv */ { 0, 0, 0, 0, Clb_SizeRDXRAX },
        /* Op_xlat */ { mem, 0, 0, 0, Clb_SizeAX }

        /// * Op_arpl */ { D|mr, reg }, // 16 only -> DstSrc
        /// * Op_bsX */ { rw, mrw, 0, 1, Clb_Flags },//->srcsrcf
        /// * Op_bt */ { mrw, riw, 0, 1, Clb_Flags },//->srcsrcf
        /// * Op_btX */ { D|mrw, riw, 0, 1, Clb_Flags },//->dstsrcf .. immediate does not contribute to size
        /// * Op_cmovCC */ { D|rw, mrw, 0, 1 } // ->dstsrc
    };

#undef mri
#undef mr
#undef mem
#undef mfp
#undef reg
#undef imm
#undef sse
#undef ssem
#undef mmx
#undef mmxm
#undef r32
#undef rw
#undef rfp
#undef port
#undef ax
#undef dx
#undef shft
#undef D
#undef U
#undef N
//#undef L

    typedef struct
    {
        const char * inMnemonic;
        AsmOp asmOp;
    } AsmOpEnt;

    /* Some opcodes have data size restrictions, which we don't check

cmov, l<segreg> ?, lea, lsl, shld

todo: push <immediate> is always the 32-bit form, even tho push <mem> is 16-bit
*/

    // WARNING: This table is expected to be SORTED ALPHABETICALLY.
    static AsmOpEnt opData[] =
    {
        { "adc", Op_UpdSrcF },
        { "add", Op_UpdSrcF },
        { "addpd", Op_DstSrcSSE },
        { "addps", Op_DstSrcSSE },
        { "addq", Op_DstSrcSSE },
        { "addsd", Op_DstSrcSSE },
        { "addss", Op_DstSrcSSE },
        { "addsubpd", Op_DstSrcSSE },
        { "addsubps", Op_DstSrcSSE },
        { "and", Op_UpdSrcF },
        { "andnpd", Op_DstSrcSSE },
        { "andnps", Op_DstSrcSSE },
        { "andpd", Op_DstSrcSSE },
        { "andps", Op_DstSrcSSE },
        { "bsf", Op_SrcSrcFW },
        { "bsr", Op_SrcSrcFW },
        { "bswap", Op_bswap },
        { "bt", Op_SrcSrcFW },
        { "btc", Op_UpdSrcFW },
        { "btr", Op_UpdSrcFW },
        { "bts", Op_UpdSrcFW },
        { "call", Op_Branch },
        { "callf", Op_Branch },
        { "cbw", Op_0_AX },
        { "cdqe", Op_0_DXAX },
        { "clc", Op_Flags },
        { "cld", Op_Flags },
        { "clflush",Op_SrcMemNT },
        { "cli", Op_Flags },
        { "clts", Op_0 },
        { "cmc", Op_Flags },
        { "cmova", Op_DstSrc },
        { "cmovae", Op_DstSrc },
        { "cmovb", Op_DstSrc },
        { "cmovbe", Op_DstSrc },
        { "cmovc", Op_DstSrc },
        { "cmove", Op_DstSrc },
        { "cmovg", Op_DstSrc },
        { "cmovge", Op_DstSrc },
        { "cmovl", Op_DstSrc },
        { "cmovle", Op_DstSrc },
        { "cmovna", Op_DstSrc },
        { "cmovnae",Op_DstSrc },
        { "cmovnb", Op_DstSrc },
        { "cmovnbe",Op_DstSrc },
        { "cmovnc", Op_DstSrc },
        { "cmovne", Op_DstSrc },
        { "cmovng", Op_DstSrc },
        { "cmovnge",Op_DstSrc },
        { "cmovnl", Op_DstSrc },
        { "cmovnle",Op_DstSrc },
        { "cmovno", Op_DstSrc },
        { "cmovnp", Op_DstSrc },
        { "cmovns", Op_DstSrc },
        { "cmovnz", Op_DstSrc },
        { "cmovo", Op_DstSrc },
        { "cmovp", Op_DstSrc },
        { "cmovpe", Op_DstSrc },
        { "cmovpo", Op_DstSrc },
        { "cmovs", Op_DstSrc },
        { "cmovz", Op_DstSrc },
        { "cmp", Op_SrcSrcF },
        { "cmppd", Op_DstSrcImmS },
        { "cmpps", Op_DstSrcImmS },
        { "cmpq", Op_DstSrcNT },
        { "cmps", Op_cmps },
        { "cmpsb", Op_cmpsX },
        { "cmpsd", Op_cmpsd }, // string cmp, and SSE cmp
        { "cmpsq", Op_cmpsX },
        { "cmpss", Op_DstSrcImmS },
        { "cmpsw", Op_cmpsX },
        { "cmpxchg", Op_cmpxchg },
        { "cmpxchg16b", Op_cmpxchg16b },
        { "cmpxchg8b", Op_cmpxchg8b },
        { "comisd", Op_SrcSrcSSEF },
        { "comiss", Op_SrcSrcSSEF },
        { "cpuid", Op_cpuid },
        { "cqo", Op_0_DXAX },
        { "cvtdq2pd", Op_DstSrcSSE },
        { "cvtdq2ps", Op_DstSrcSSE },
        { "cvtpd2dq", Op_DstSrcSSE },
        { "cvtpd2pi", Op_DstSrcSSE },
        { "cvtpd2ps", Op_DstSrcSSE },
        { "cvtpi2pd", Op_DstSrcSSE },
        { "cvtpi2ps", Op_DstSrcSSE },
        { "cvtps2dq", Op_DstSrcSSE },
        { "cvtps2pd", Op_DstSrcSSE },
        { "cvtps2pi", Op_DstSrcSSE },
        { "cvtsd2si", Op_DstSrcSSE },
        { "cvtsd2ss", Op_DstSrcSSE },
        { "cvtsi2sd", Op_DstSrcSSE },
        { "cvtsi2ss", Op_DstSrcSSE },
        { "cvtss2sd", Op_DstSrcSSE },
        { "cvtss2si", Op_DstSrcSSE },
        { "cvttpd2dq", Op_DstSrcSSE },
        { "cvttpd2pi", Op_DstSrcSSE },
        { "cvttps2dq", Op_DstSrcSSE },
        { "cvttps2pi", Op_DstSrcSSE },
        { "cvttsd2si", Op_DstSrcSSE },
        { "cvttss2si", Op_DstSrcSSE },
        { "cwd", Op_0_DXAX },
        { "cwde", Op_0_DXAX },
        //{ "da", Op_ },// dunno what this is -- takes labels?
        { "db", Op_db },
        { "dd", Op_dd },
        { "de", Op_de },
        { "dec", Op_UpdF },
        { "df", Op_df },
        { "di", Op_di },
        { "div", Op_Src_DXAXF },
        { "divpd", Op_DstSrcSSE },
        { "divps", Op_DstSrcSSE },
        { "divsd", Op_DstSrcSSE },
        { "divss", Op_DstSrcSSE },
        { "dl", Op_dl },
        { "dq", Op_dl },
        { "ds", Op_ds },
        { "dt", Op_de },
        { "dw", Op_ds },
        { "emms", Op_0 }, // clobber all mmx/fp?
        { "enter", Op_enter },
        { "even", Op_Even },
        { "f2xm1", Op_F0_ST }, // %% most of these are update...
        { "fabs", Op_F0_ST },
        { "fadd", Op_FMath },
        { "faddp", Op_FPMath },
        { "fbld", Op_Fs_P },
        { "fbstp", Op_Fd_P },
        { "fchs", Op_F0_ST },
        { "fclex", Op_0 },
        { "fcmovb", Op_FdSTiSTi }, // but only ST(0) can be the destination -- should be FdST0STi
        { "fcmovbe", Op_FdSTiSTi },
        { "fcmove", Op_FdSTiSTi },
        { "fcmovnb", Op_FdSTiSTi },
        { "fcmovnbe", Op_FdSTiSTi },
        { "fcmovne", Op_FdSTiSTi },
        { "fcmovnu", Op_FdSTiSTi },
        { "fcmovu", Op_FdSTiSTi },
        { "fcom", Op_FCmp },
        { "fcomi", Op_FCmpFlg },
        { "fcomip", Op_FCmpFlgP },
        { "fcomp", Op_FCmpP },
        { "fcompp", Op_F0_P }, // pops twice
        { "fcos", Op_F0_ST },
        { "fdecstp",Op_F0_P }, // changes stack
        { "fdisi", Op_fdisi },
        { "fdiv", Op_FMath },
        { "fdivp", Op_FPMath },
        { "fdivr", Op_FMath },
        { "fdivrp", Op_FPMath },
        { "feni", Op_feni },
        { "ffree", Op_FdST },
        { "fiadd", Op_Fis_ST },
        { "ficom", Op_Fis },
        { "ficomp", Op_Fis_P },
        { "fidiv", Op_Fis_ST },
        { "fidivr", Op_Fis_ST },
        { "fild", Op_Fis_P },
        { "fimul", Op_Fis_ST },
        { "fincstp",Op_F0_P },
        { "finit", Op_F0_P },
        { "fist", Op_Fid }, // only 16,32bit
        { "fistp", Op_Fid_P },
        { "fisttp", Op_Fid_P },
        { "fisub", Op_Fis_ST },
        { "fisubr", Op_Fis_ST },
        { "fld", Op_fld },
        { "fld1", Op_F0_P },
        { "fldcw", Op_SrcMemNT },
        { "fldenv", Op_SrcMemNT },
        { "fldl2e", Op_F0_P },
        { "fldl2t", Op_F0_P },
        { "fldlg2", Op_F0_P },
        { "fldln2", Op_F0_P },
        { "fldpi", Op_F0_P },
        { "fldz", Op_F0_P },
        { "fmul", Op_FMath },
        { "fmulp", Op_FPMath },
        { "fnclex", Op_0 },
        { "fndisi", Op_fdisi }, // ??
        { "fneni", Op_feni }, // ??
        { "fninit", Op_0 },
        { "fnop", Op_0 },
        { "fnsave", Op_DstMemNT },
        { "fnstcw", Op_DstMemNT },
        { "fnstenv",Op_DstMemNT },
        { "fnstsw", Op_fXstsw },
        { "fpatan", Op_F0_P }, // pop and modify new ST
        { "fprem", Op_F0_ST },
        { "fprem1", Op_F0_ST },
        { "fptan", Op_F0_P }, // modify ST and push 1.0
        { "frndint",Op_F0_ST },
        { "frstor", Op_SrcMemNT }, // but clobbers everything
        { "fsave", Op_DstMemNT },
        { "fscale", Op_F0_ST },
        { "fsetpm", Op_fsetpm },
        { "fsin", Op_F0_ST },
        { "fsincos",Op_F0_P },
        { "fsqrt", Op_F0_ST },
        { "fst", Op_Ffd },
        { "fstcw", Op_DstMemNT },
        { "fstenv", Op_DstMemNT },
        { "fstp", Op_Ffd_P },
        { "fstsw", Op_fXstsw },
        { "fsub", Op_FMath },
        { "fsubp", Op_FPMath },
        { "fsubr", Op_FMath },
        { "fsubrp", Op_FPMath },
        { "ftst", Op_0 },
        { "fucom", Op_FCmp },
        { "fucomi", Op_FCmpFlg },
        { "fucomip",Op_FCmpFlgP },
        { "fucomp", Op_FCmpP },
        { "fucompp",Op_F0_P }, // pops twice
        { "fwait", Op_0 },
        { "fxam", Op_0 },
        { "fxch", Op_fxch },
        { "fxrstor",Op_SrcMemNT }, // clobbers FP,MMX,SSE
        { "fxsave", Op_DstMemNT },
        { "fxtract",Op_F0_P }, // pushes
        { "fyl2x", Op_F0_P }, // pops
        { "fyl2xp1",Op_F0_P }, // pops
        { "haddpd", Op_DstSrcSSE },
        { "haddps", Op_DstSrcSSE },
        { "hlt", Op_0 },
        { "hsubpd", Op_DstSrcSSE },
        { "hsubps", Op_DstSrcSSE },
        { "idiv", Op_Src_DXAXF },
        { "imul", Op_imul },
        { "in", Op_in },
        { "inc", Op_UpdF },
        { "ins", Op_ins },
        { "insb", Op_insX },
        { "insd", Op_insX },
        { "insw", Op_insX },
        { "int", Op_SrcImm },
        { "into", Op_0 },
        { "invd", Op_0 },
        { "invlpg", Op_SrcMemNT },
        { "iret", Op_iret },
        { "iretd", Op_iretd },
        { "iretq", Op_iretq },
        { "ja", Op_CBranch },
        { "jae", Op_CBranch },
        { "jb", Op_CBranch },
        { "jbe", Op_CBranch },
        { "jc", Op_CBranch },
        { "jcxz", Op_CBranch },
        { "je", Op_CBranch },
        { "jecxz", Op_CBranch },
        { "jg", Op_CBranch },
        { "jge", Op_CBranch },
        { "jl", Op_CBranch },
        { "jle", Op_CBranch },
        { "jmp", Op_Branch },
        { "jmpe", Op_Branch },
        { "jmpf", Op_Branch },
        { "jna", Op_CBranch },
        { "jnae", Op_CBranch },
        { "jnb", Op_CBranch },
        { "jnbe", Op_CBranch },
        { "jnc", Op_CBranch },
        { "jne", Op_CBranch },
        { "jng", Op_CBranch },
        { "jnge", Op_CBranch },
        { "jnl", Op_CBranch },
        { "jnle", Op_CBranch },
        { "jno", Op_CBranch },
        { "jnp", Op_CBranch },
        { "jns", Op_CBranch },
        { "jnz", Op_CBranch },
        { "jo", Op_CBranch },
        { "jp", Op_CBranch },
        { "jpe", Op_CBranch },
        { "jpo", Op_CBranch },
        { "jrcxz", Op_CBranch },
        { "js", Op_CBranch },
        { "jz", Op_CBranch },
        { "lahf", Op_0_AX },
        { "lar", Op_DstSrcFW }, // reg dest only
        { "lddqu", Op_DstSrcSSE },
        { "ldmxcsr", Op_SrcMemNT },
        { "lds", Op_DstSrc }, // reg dest only
        { "lea", Op_DstSrc }, // "
        { "leaq", Op_DstSrcSSE }, // "
        { "leave", Op_0 }, // EBP,ESP clobbers
        { "lfence",Op_0 },
        { "lfs", Op_DstSrc },
        { "lgdt", Op_SrcMemNT },
        { "lgs", Op_DstSrc },
        { "lidt", Op_SrcMemNT },
        { "lldt", Op_SrcRMWNT },
        { "lmsw", Op_SrcRMWNT },
        { "lock", Op_0 },
        { "lods", Op_lods },
        { "lodsb", Op_lodsX },
        { "lodsd", Op_lodsX },
        { "lodsq", Op_lodsX },
        { "lodsw", Op_lodsX },
        { "loop", Op_Loop },
        { "loope", Op_Loop },
        { "loopne",Op_Loop },
        { "loopnz",Op_Loop },
        { "loopz", Op_Loop },
        { "lsl", Op_DstSrcFW }, // reg dest only
        { "lss", Op_DstSrc },
        { "ltr", Op_DstMemNT },
        { "maskmovdqu", Op_SrcSrcMMX }, // writes to [edi]
        { "maskmovq", Op_SrcSrcMMX },
        { "maxpd", Op_DstSrcSSE },
        { "maxps", Op_DstSrcSSE },
        { "maxsd", Op_DstSrcSSE },
        { "maxss", Op_DstSrcSSE },
        { "mfence",Op_0},
        { "minpd", Op_DstSrcSSE },
        { "minps", Op_DstSrcSSE },
        { "minsd", Op_DstSrcSSE },
        { "minss", Op_DstSrcSSE },
        { "monitor", Op_0 },
        { "mov", Op_DstSrc },
        { "movapd", Op_DstSrcSSE },
        { "movaps", Op_DstSrcSSE },
        { "movb", Op_DstSrcNT },
        { "movd", Op_DstSrcNT }, // also mmx and sse
        { "movddup", Op_DstSrcSSE },
        { "movdq2q", Op_DstSrcNT }, // mmx/sse
        { "movdqa", Op_DstSrcSSE },
        { "movdqu", Op_DstSrcSSE },
        { "movhlps", Op_DstSrcSSE },
        { "movhpd", Op_DstSrcSSE },
        { "movhps", Op_DstSrcSSE },
        { "movl", Op_DstSrc },
        { "movlhps", Op_DstSrcSSE },
        { "movlpd", Op_DstSrcSSE },
        { "movlps", Op_DstSrcSSE },
        { "movmskpd",Op_DstSrcSSE },
        { "movmskps",Op_DstSrcSSE },
        { "movntdq", Op_DstSrcNT }, // limited to sse, but mem dest
        { "movnti", Op_DstSrcNT }, // limited to gpr, but mem dest
        { "movntpd", Op_DstSrcNT }, // limited to sse, but mem dest
        { "movntps", Op_DstSrcNT }, // limited to sse, but mem dest
        { "movntq", Op_DstSrcNT }, // limited to mmx, but mem dest
        { "movq", Op_DstSrcNT }, // limited to sse and mmx
        { "movq2dq", Op_DstSrcNT }, // limited to sse <- mmx regs
        { "movs", Op_movs },
        { "movsb", Op_movsX },
        { "movsd", Op_movsd },
        { "movshdup", Op_DstSrcSSE },
        { "movsldup", Op_DstSrcSSE },
        { "movsq", Op_movsd },
        { "movss", Op_DstSrcSSE },
        { "movsw", Op_movsX },
        { "movsx", Op_movsx }, // word-only, reg dest
        { "movsxd", Op_movsx },
        { "movupd",Op_DstSrcSSE },
        { "movups",Op_DstSrcSSE },
        { "movzbl", Op_DstSrcNT },
        { "movzx", Op_movzx },
        { "mul", Op_mul },
        { "mulpd", Op_DstSrcSSE },
        { "mulps", Op_DstSrcSSE },
        { "mulsd", Op_DstSrcSSE },
        { "mulss", Op_DstSrcSSE },
        { "mwait", Op_0 },
        { "naked", Op_Naked },
        { "neg", Op_UpdF },
        { "nop", Op_0 },
        { "not", Op_Upd },
        { "or", Op_UpdSrcF },
        { "orpd", Op_DstSrcSSE },
        { "orps", Op_DstSrcSSE },
        { "out", Op_out },
        { "outs", Op_outs },
        { "outsb", Op_outsX },
        { "outsd", Op_outsX },
        { "outsw", Op_outsX },
        { "pabsb", Op_DstSrcSSE },
        { "pabsq", Op_DstSrcSSE },
        { "pabsw", Op_DstSrcSSE },
        { "packssdw", Op_DstSrcMMX }, // %% also SSE
        { "packsswb", Op_DstSrcMMX },
        { "packuswb", Op_DstSrcMMX },
        { "paddb", Op_DstSrcMMX },
        { "paddd", Op_DstSrcMMX },
        { "paddq", Op_DstSrcMMX },
        { "paddsb", Op_DstSrcMMX },
        { "paddsw", Op_DstSrcMMX },
        { "paddusb", Op_DstSrcMMX },
        { "paddusw", Op_DstSrcMMX },
        { "paddw", Op_DstSrcMMX },
        { "palignr", Op_DstSrcImmS },
        { "pand", Op_DstSrcMMX },
        { "pandn", Op_DstSrcMMX },
        { "pause", Op_DstSrcMMX },
        { "pavgb", Op_DstSrcMMX },
        { "pavgusb", Op_DstSrcMMX }, // AMD 3dNow!
        { "pavgw", Op_DstSrcMMX },
        { "pcmpeqb", Op_DstSrcMMX },
        { "pcmpeqd", Op_DstSrcMMX },
        { "pcmpeqw", Op_DstSrcMMX },
        { "pcmpgtb", Op_DstSrcMMX },
        { "pcmpgtd", Op_DstSrcMMX },
        { "pcmpgtw", Op_DstSrcMMX },
        { "pextrw", Op_DstSrcImmM }, // gpr32 dest
        { "pf2id", Op_DstSrcMMX }, // %% AMD 3dNow! opcodes
        { "pfacc", Op_DstSrcMMX },
        { "pfadd", Op_DstSrcMMX },
        { "pfcmpeq", Op_DstSrcMMX },
        { "pfcmpge", Op_DstSrcMMX },
        { "pfcmpgt", Op_DstSrcMMX },
        { "pfmax", Op_DstSrcMMX },
        { "pfmin", Op_DstSrcMMX },
        { "pfmul", Op_DstSrcMMX },
        { "pfnacc", Op_DstSrcMMX }, // 3dNow values are returned in MM0 register,
        { "pfpnacc", Op_DstSrcMMX }, // so should be correct to use Op_DstSrcMMX.
        { "pfrcp", Op_DstSrcMMX },
        { "pfrcpit1", Op_DstSrcMMX },
        { "pfrcpit2", Op_DstSrcMMX },
        { "pfrsqit1", Op_DstSrcMMX },
        { "pfrsqrt", Op_DstSrcMMX },
        { "pfsub", Op_DstSrcMMX },
        { "pfsubr", Op_DstSrcMMX },
        { "phaddd", Op_DstSrcSSE },
        { "phaddsw", Op_DstSrcSSE },
        { "phaddw", Op_DstSrcSSE },
        { "phsubd", Op_DstSrcSSE },
        { "phsubsw", Op_DstSrcSSE },
        { "phsubw", Op_DstSrcSSE },
        { "pi2fd", Op_DstSrcMMX }, // %%
        { "pinsrw", Op_DstSrcImmM }, // gpr32(16), mem16 src, sse too
        { "pmaddubsw", Op_DstSrcSSE },
        { "pmaddwd", Op_DstSrcMMX },
        { "pmaxsw", Op_DstSrcMMX },
        { "pmaxub", Op_DstSrcMMX },
        { "pminsw", Op_DstSrcMMX },
        { "pminub", Op_DstSrcMMX },
        { "pmovmskb", Op_DstSrcMMX },
        { "pmulhrsw", Op_DstSrcMMX },
        { "pmulhrw", Op_DstSrcMMX }, // AMD 3dNow!
        { "pmulhuw", Op_DstSrcMMX },
        { "pmulhw", Op_DstSrcMMX },
        { "pmullw", Op_DstSrcMMX },
        { "pmuludq", Op_DstSrcMMX }, // also sse
        { "pop", Op_DstW },
        { "popf", Op_0 }, // rewrite the insn with a special case
        { "popfq", Op_0 }, // Op_SizedStack?
        { "popq", Op_push },
        { "por", Op_DstSrcMMX },
        { "prefetchnta", Op_SrcMemNT },
        { "prefetcht0", Op_SrcMemNT },
        { "prefetcht1", Op_SrcMemNT },
        { "prefetcht2", Op_SrcMemNT },
        { "psadbw", Op_DstSrcMMX },
        { "pshufb", Op_DstSrcSSE },
        { "pshufd", Op_DstSrcImmS },
        { "pshufhw", Op_DstSrcImmS },
        { "pshuflw", Op_DstSrcImmS },
        { "pshufw", Op_DstSrcImmS },
        { "psignb", Op_DstSrcSSE },
        { "psignd", Op_DstSrcSSE },
        { "psignw", Op_DstSrcSSE },
        { "pslld", Op_DstSrcMMX }, // immediate operands...
        { "pslldq", Op_DstSrcMMX },
        { "psllq", Op_DstSrcMMX },
        { "psllw", Op_DstSrcMMX },
        { "psrad", Op_DstSrcMMX },
        { "psraw", Op_DstSrcMMX },
        { "psrld", Op_DstSrcMMX },
        { "psrldq", Op_DstSrcMMX },
        { "psrlq", Op_DstSrcMMX },
        { "psrlw", Op_DstSrcMMX },
        { "psubb", Op_DstSrcMMX },
        { "psubd", Op_DstSrcMMX },
        { "psubq", Op_DstSrcMMX },
        { "psubsb", Op_DstSrcMMX },
        { "psubsw", Op_DstSrcMMX },
        { "psubusb", Op_DstSrcMMX },
        { "psubusw", Op_DstSrcMMX },
        { "psubw", Op_DstSrcMMX },
        { "pswapd", Op_DstSrcMMX }, // AMD 3dNow!
        { "punpckhbw", Op_DstSrcMMX },
        { "punpckhdq", Op_DstSrcMMX },
        { "punpckhqdq",Op_DstSrcMMX },
        { "punpckhwd", Op_DstSrcMMX },
        { "punpcklbw", Op_DstSrcMMX },
        { "punpckldq", Op_DstSrcMMX },
        { "punpcklqdq",Op_DstSrcMMX },
        { "punpcklwd", Op_DstSrcMMX },
        { "push", Op_push },
        { "pushf", Op_0 },
        { "pushfq", Op_0 }, // Op_SizedStack?
        { "pushq", Op_push },
        { "pxor", Op_DstSrcMMX },
        { "rcl", Op_Shift }, // limited src operands -- change to shift
        { "rcpps", Op_DstSrcSSE },
        { "rcpss", Op_DstSrcSSE },
        { "rcr", Op_Shift },
        { "rdmsr", Op_0_DXAX },
        { "rdpmc", Op_0_DXAX },
        { "rdtsc", Op_0_DXAX },
        { "rep", Op_0 },
        { "repe", Op_0 },
        { "repne", Op_0 },
        { "repnz", Op_0 },
        { "repz", Op_0 },
        { "ret", Op_ret },
        { "retf", Op_retf },
        { "retn", Op_retf },
        { "rol", Op_Shift },
        { "ror", Op_Shift },
        { "rsm", Op_0 },
        { "rsqrtps", Op_DstSrcSSE },
        { "rsqrtss", Op_DstSrcSSE },
        { "sahf", Op_Flags },
        { "sal", Op_Shift },
        { "salq", Op_DstSrcNT },
        { "sar", Op_Shift },
        { "sbb", Op_UpdSrcF },
        { "scas", Op_scas },
        { "scasb", Op_scasX },
        { "scasd", Op_scasX },
        { "scasq", Op_scasX },
        { "scasw", Op_scasX },
        { "seta", Op_DstRMBNT }, // also gpr8
        { "setae", Op_DstRMBNT },
        { "setb", Op_DstRMBNT },
        { "setbe", Op_DstRMBNT },
        { "setc", Op_DstRMBNT },
        { "sete", Op_DstRMBNT },
        { "setg", Op_DstRMBNT },
        { "setge", Op_DstRMBNT },
        { "setl", Op_DstRMBNT },
        { "setle", Op_DstRMBNT },
        { "setna", Op_DstRMBNT },
        { "setnae", Op_DstRMBNT },
        { "setnb", Op_DstRMBNT },
        { "setnbe", Op_DstRMBNT },
        { "setnc", Op_DstRMBNT },
        { "setne", Op_DstRMBNT },
        { "setng", Op_DstRMBNT },
        { "setnge", Op_DstRMBNT },
        { "setnl", Op_DstRMBNT },
        { "setnle", Op_DstRMBNT },
        { "setno", Op_DstRMBNT },
        { "setnp", Op_DstRMBNT },
        { "setns", Op_DstRMBNT },
        { "setnz", Op_DstRMBNT },
        { "seto", Op_DstRMBNT },
        { "setp", Op_DstRMBNT },
        { "setpe", Op_DstRMBNT },
        { "setpo", Op_DstRMBNT },
        { "sets", Op_DstRMBNT },
        { "setz", Op_DstRMBNT },
        { "sfence", Op_0 },
        { "sgdt", Op_DstMemNT },
        { "shl", Op_Shift },
        { "shld", Op_UpdSrcShft },
        { "shr", Op_Shift },
        { "shrd", Op_UpdSrcShft },
        { "shufpd", Op_DstSrcImmS },
        { "shufps", Op_DstSrcImmS },
        { "sidt", Op_DstMemNT },
        { "sldt", Op_DstRMWNT },
        { "smsw", Op_DstRMWNT },
        { "sqrtpd", Op_DstSrcSSE },
        { "sqrtps", Op_DstSrcSSE },
        { "sqrtsd", Op_DstSrcSSE },
        { "sqrtss", Op_DstSrcSSE },
        { "stc", Op_Flags },
        { "std", Op_Flags },
        { "sti", Op_Flags },
        { "stmxcsr",Op_DstMemNT },
        { "stos", Op_stos },
        { "stosb", Op_stosX },
        { "stosd", Op_stosX },
        { "stosq", Op_stosX },
        { "stosw", Op_stosX },
        { "str", Op_DstMemNT }, // also r16
        { "sub", Op_UpdSrcF },
        { "subpd", Op_DstSrcSSE },
        { "subps", Op_DstSrcSSE },
        { "subq", Op_DstSrcSSE },
        { "subsd", Op_DstSrcSSE },
        { "subss", Op_DstSrcSSE },
        { "swapgs", Op_0 },
        { "syscall", Op_0 },
        { "sysenter",Op_0 },
        { "sysexit", Op_0 },
        { "sysret", Op_0 },
        { "sysretq", Op_0 },
        { "test", Op_SrcSrcF },
        { "ucomisd", Op_SrcSrcSSEF },
        { "ucomiss", Op_SrcSrcSSEF },
        { "ud2", Op_0 },
        { "unpckhpd", Op_DstSrcSSE },
        { "unpckhps", Op_DstSrcSSE },
        { "unpcklpd", Op_DstSrcSSE },
        { "unpcklps", Op_DstSrcSSE },
        { "verr", Op_SrcMemNTF },
        { "verw", Op_SrcMemNTF },
        { "wbinvd", Op_0 },
        { "wrmsr", Op_0 },
        { "xadd", Op_UpdUpdF },
        { "xchg", Op_UpdUpd },
        { "xgetbv", Op_xgetbv },
        { "xlat", Op_xlat },
        { "xlatb", Op_0_AX },
        { "xor", Op_DstSrcF },
        { "xorpd", Op_DstSrcSSE },
        { "xorps", Op_DstSrcSSE },
        { "xorq", Op_DstSrcNT },
    };

    typedef enum
    {
        Default_Ptr = 0,
        Byte_Ptr = 1,
        Short_Ptr = 2,
        Int_Ptr = 4,
        QWord_Ptr = 8,
        Float_Ptr = 4,
        Double_Ptr = 8,
        Extended_Ptr = 10,
        Near_Ptr = 98,
        Far_Ptr = 99,
        N_PtrTypes
    } PtrType;

    static const int N_PtrNames = 8;
    static const char * ptrTypeNameTable[N_PtrNames] =
    {
        "word", "dword", "qword",
        "float", "double", "extended",
        "near", "far"
    };

    static Identifier * ptrTypeIdentTable[N_PtrNames];
    static PtrType ptrTypeValueTable[N_PtrNames] =
    {
        Short_Ptr, Int_Ptr, QWord_Ptr,
        Float_Ptr, Double_Ptr, Extended_Ptr,
        Near_Ptr, Far_Ptr
    };

    typedef enum
    {
        Opr_Invalid,
        Opr_Immediate,
        Opr_Reg,
        Opr_Mem
    } OperandClass;

    /* kill inlining if we reference a local? */

    /* DMD seems to allow only one 'symbol' per operand .. include __LOCAL_SIZE */

    /* DMD offset usage: <parm>[<reg>] seems to always be relative to EBP+8 .. even
if naked.. */

// mov eax, 4
// mov eax, fs:4
// -- have to assume we know whether or not to use '$'

    static Token eof_tok;
    static Expression * Handled;
    static Identifier * ident_seg;

    struct AsmProcessor
    {
        typedef struct
        {
            int inBracket;
            int hasBracket;
            int hasNumber;
            int isOffset;

            Reg segmentPrefix;
            Reg reg;
            sinteger_t constDisplacement; // use to build up.. should be int constant in the end..
            Array symbolDisplacement; // array of expressions or..
            Reg baseReg;
            Reg indexReg;
            int scale;

            OperandClass cls;
            PtrType dataSize;
            PtrType dataSizeHint; // DMD can use the type of a referenced variable
        } Operand;

        static const unsigned Max_Operands = 3;

        AsmStatement * stmt;
        Scope * sc;

        Token * token;
        std::ostringstream insnTemplate;

        AsmOp op;
        AsmOpInfo * opInfo;
        Operand operands[Max_Operands];
        Identifier * opIdent;
        Operand * operand;

        AsmProcessor ( Scope * sc, AsmStatement * stmt )
        {
            this->sc = sc;
            this->stmt = stmt;
            token = stmt->tokens;

            opInfo = NULL;

            if ( ! regInfo[0].ident )
            {
                char buf[8], *p;

                for ( int i = 0; i < N_Regs; i++ )
                {
                    strncpy ( buf, regInfo[i].name, sizeof ( buf ) - 1 );
                    for ( p = buf; *p; p++ )
#if defined(_MSC_VER)
                        *p = tolower ( *p );
#else
                        *p = std::tolower ( *p );
#endif
                    regInfo[i].gccName = std::string ( buf, p - buf );
                    if ( ( i <= Reg_ST || i > Reg_ST7 ) && i != Reg_EFLAGS )
                        regInfo[i].ident = Lexer::idPool ( regInfo[i].name );
                }

                for ( int i = 0; i < N_PtrNames; i++ )
                    ptrTypeIdentTable[i] = Lexer::idPool ( ptrTypeNameTable[i] );

                Handled = new Expression ( 0, TOKvoid, sizeof ( Expression ) );

                ident_seg = Lexer::idPool ( "seg" );

                eof_tok.value = TOKeof;
                eof_tok.next = 0;
            }
        }

        void run()
        {
            parse();
        }

        void nextToken()
        {
            if ( token->next )
                token = token->next;
            else
                token = & eof_tok;
        }

        Token * peekToken()
        {
            if ( token->next )
                return token->next;
            else
                return & eof_tok;
        }

        void expectEnd()
        {
            if ( token->value != TOKeof )
                stmt->error ( "expected end of statement" ); // %% extra at end...
        }

        void parse()
        {
            op = parseOpcode();

            switch ( op )
            {
                case Op_Align:
                    doAlign();
                    expectEnd();
                    break;
                case Op_Even:
                    doEven();
                    expectEnd();
                    break;
                case Op_Naked:
                    doNaked();
                    expectEnd();
                    break;
                case Op_Invalid:
                    break;
                default:
                    if ( op >= Op_db && op <= Op_de )
                        doData();
                    else
                        doInstruction();
            }
        }

        AsmOp parseOpcode()
        {
            static const int N_ents = sizeof ( opData ) /sizeof ( AsmOpEnt );

            switch ( token->value )
            {
                case TOKalign:
                    nextToken();
                    return Op_Align;
                case TOKin:
                    nextToken();
                    opIdent = Id::___in;
                    return Op_in;
                case TOKint32: // "int"
                    nextToken();
                    opIdent = Id::__int;
                    return Op_SrcImm;
                case TOKout:
                    nextToken();
                    opIdent = Id::___out;
                    return Op_out;
                case TOKidentifier:
                    // search for mnemonic below
                    break;
                default:
                    stmt->error ( "expected opcode" );
                    return Op_Invalid;
            }

            opIdent = token->ident;
            const char * opcode = token->ident->string;

            nextToken();

            // %% okay to use bsearch?
            int i = 0, j = N_ents, k, l;
            do
            {
                k = ( i + j ) / 2;
                l = strcmp ( opcode, opData[k].inMnemonic );
                if ( ! l )
                    return opData[k].asmOp;
                else if ( l < 0 )
                    j = k;
                else
                    i = k + 1;
            }
            while ( i != j );

            stmt->error ( "unknown opcode '%s'", opcode );

            return Op_Invalid;
        }

        // need clobber information.. use information is good too...
        void doInstruction()
        {
            bool ok = true;
            unsigned operand_i = 0;

            opInfo = & asmOpInfo[op];
            memset ( operands, 0, sizeof ( operands ) );

            if ( token->value == TOKeof && ( op == Op_FMath0) )
            {
                for ( operand_i = 0; operand_i < 1; operand_i++)
                {
                    operand = & operands[operand_i];
                    operand->reg = operand->baseReg = operand->indexReg =
                                                          operand->segmentPrefix = Reg_Invalid;

                    operand->cls = Opr_Reg;
                    if ( operand_i == 0)
                    {
                        operand->reg = Reg_ST;
                    }
                    else
                    {
                        operand->reg = Reg_ST1;
                    }
                    operand->hasNumber = 0;
                    operand->constDisplacement = 0;
                    parseOperand();

                    if ( matchOperands ( operand_i ) )
                    {
                        AsmCode * asmcode = new AsmCode ( N_Regs );

                        if ( formatInstruction ( operand_i, asmcode ) )
                            stmt->asmcode = ( code * ) asmcode;
                    }
                }
                return;
            }

            while ( token->value != TOKeof )
            {
                if ( operand_i < Max_Operands )
                {
                    operand = & operands[operand_i];
                    operand->reg = operand->baseReg = operand->indexReg =
                                                          operand->segmentPrefix = Reg_Invalid;
                    parseOperand();
                    operand_i++;
                }
                else
                {
                    ok = false;
                    stmt->error ( "too many operands for instruction" );
                    break;
                }

                if ( token->value == TOKcomma )
                {
                    nextToken();
                }
                else if ( token->value != TOKeof )
                {
                    ok = false;
                    stmt->error ( "expected comma after operand" );
                    return;
                }
            }
// if (operand_i < opInfo->minOperands) {
// ok = false;
// stmt->error("too few operands for instruction");
// }

            if ( matchOperands ( operand_i ) )
            {
                AsmCode * asmcode = new AsmCode ( N_Regs );

                if ( formatInstruction ( operand_i, asmcode ) )
                    stmt->asmcode = ( code * ) asmcode;
            }
        }

        void setAsmCode()
        {
            AsmCode * asmcode = new AsmCode ( N_Regs );
            asmcode->insnTemplate = insnTemplate.str();
            Logger::cout() << "insnTemplate = " << asmcode->insnTemplate << '\n';
            stmt->asmcode = ( code* ) asmcode;
        }

        // note: doesn't update AsmOp op
        bool matchOperands ( unsigned nOperands )
        {
            bool wrong_number = true;

            for ( unsigned i = 0; i < nOperands; i++ )
                classifyOperand ( & operands[i] );

            while ( 1 )
            {
                if ( nOperands == opInfo->nOperands() )
                {
                    wrong_number = false;
                    /* Cases in which number of operands is not
enough for a match: Op_FCmp/Op_FCmp1,
Op_FCmpP/Op_FCmpP1 */
                    for ( unsigned i = 0; i < nOperands; i++ )
                    {
                        Operand * operand = & operands[i];

                        switch ( opInfo->operands[i] & Opr_ClassMask )
                        {
                            case OprC_Mem: // no FPMem currently
                                if ( operand->cls != Opr_Mem )
                                    goto no_match;
                                break;
                            case OprC_RFP:
                                if ( ! ( operand->reg >= Reg_ST && operand->reg <= Reg_ST7 ) )
                                    goto no_match;
                                break;
                            default:
                                break;
                        }
                    }

                    return true;
                }
            no_match:
                if ( opInfo->linkType == Next_Form )
                    opInfo = & asmOpInfo[ op = ( AsmOp ) opInfo->link ];
                else
                    break;
            }
            if ( wrong_number )
                stmt->error ( "wrong number of operands" );
            else
                stmt->error ( "wrong operand types" );
            return false;
        }

        void addOperand ( const char * fmt, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input )
        {
            if ( sc->func->naked )
            {
                switch ( type )
                {
                    case Arg_Integer:
                        if ( e->type->isunsigned() )
                            insnTemplate << "$" << e->toUInteger();
                        else
                            insnTemplate << "$" << e->toInteger();
                        break;

                    case Arg_Pointer:
                        stmt->error ( "unsupported pointer reference to '%s' in naked asm", e->toChars() );
                        break;

                    case Arg_Memory:
                        if ( e->op == TOKvar )
                        {
                            VarExp* v = ( VarExp* ) e;
                            if ( VarDeclaration* vd = v->var->isVarDeclaration() )
                            {
                                if ( !vd->isDataseg() )
                                {
                                    stmt->error ( "only global variables can be referenced by identifier in naked asm" );
                                    break;
                                }

                                // osx needs an extra underscore
                                if ( global.params.os == OSMacOSX || global.params.os == OSWindows )
                                    insnTemplate << "_";

                                // print out the mangle
                                insnTemplate << vd->mangle();
                                vd->nakedUse = true;
                                break;
                            }
                        }
                        stmt->error ( "unsupported memory reference to '%s' in naked asm", e->toChars() );
                        break;

                    default:
                        assert ( 0 && "asm unsupported arg" );
                        break;
                }
            }
            else
            {
                insnTemplate << fmt
                             << "<<" << (mode==Mode_Input ? "in" : "out") << asmcode->args.size() << ">>";
                asmcode->args.push_back ( AsmArg ( type, e, mode ) );
            }
        }
        void addOperand2 ( const char * fmtpre, const char * fmtpost, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input )
        {
            if ( sc->func->naked )
            {
                // taken from above
                stmt->error ( "only global variables can be referenced by identifier in naked asm" );
                return;
            }

            insnTemplate << fmtpre
                         << "<<" << (mode==Mode_Input ? "in" : "out") << ">>"
                         << fmtpost;
            asmcode->args.push_back ( AsmArg ( type, e, mode ) );
        }

        void addLabel ( char* id )
        {
            printLabelName(insnTemplate, sc->func->mangle(), id);
        }

        /* Determines whether the operand is a register, memory reference
or immediate. Immediate addresses are currently classified as
memory. This function is called before the exact instructions
is known and thus, should not use opInfo. */
        void classifyOperand ( Operand * operand )
        {
            operand->cls = classifyOperand1 ( operand );
        }

        OperandClass classifyOperand1 ( Operand * operand )
        {
            bool is_localsize = false;
            bool really_have_symbol = false;

            if ( operand->symbolDisplacement.dim )
            {
                is_localsize = isLocalSize ( ( Expression * ) operand->symbolDisplacement.data[0] );
                really_have_symbol = ! is_localsize;
            }

            if ( operand->isOffset && ! operand->hasBracket )
                return Opr_Immediate;

            if ( operand->hasBracket || really_have_symbol ) // %% redo for 'offset' function
            {
                if ( operand->reg != Reg_Invalid )
                {
                    invalidExpression();
                    return Opr_Invalid;
                }

                return Opr_Mem;
            }

            if ( operand->reg != Reg_Invalid && operand->constDisplacement != 0 )
            {
                invalidExpression();
                return Opr_Invalid;
            }

            if ( operand->segmentPrefix != Reg_Invalid )
            {
                if ( operand->reg != Reg_Invalid )
                {
                    invalidExpression();
                    return Opr_Invalid;
                }

                return Opr_Mem;
            }

            if ( operand->reg != Reg_Invalid && ! operand->hasNumber )
                return Opr_Reg;

            // should check immediate given (operand->hasNumber);
            //
            if ( operand->hasNumber || is_localsize )
            {
                // size determination not correct if there are symbols Opr_Immediate
                if ( operand->dataSize == Default_Ptr )
                {
                    if ( operand->constDisplacement < 0x100 )
                        operand->dataSize = Byte_Ptr;
                    else if ( operand->constDisplacement < 0x10000 )
                        operand->dataSize = Short_Ptr;
                    else if ( operand->constDisplacement <= 0xFFFFFFFF )
                        operand->dataSize = Int_Ptr;
                    else
                        //This could be possible since we are using 48 bits
                        operand->dataSize = QWord_Ptr;
                }
                return Opr_Immediate;
            }

            // probably a bug,?
            stmt->error ( "invalid operand" );
            return Opr_Invalid;
        }

        void writeReg ( Reg reg )
        {
            insnTemplate << "%" << regInfo[reg].gccName;
        }

        bool opTakesLabel()
        {
            switch ( op )
            {
                case Op_Branch:
                case Op_CBranch:
                case Op_Loop:
                    return true;
                default:
                    return false;
            }
        }

        bool getTypeSuffix ( TypeNeeded needed, PtrType ptrtype, std::string & type_suffix )
        {
            switch ( needed )
            {
                case Byte_NoType:
                    return ptrtype == Byte_Ptr;
                case Word_Types:
                    if ( ptrtype == Byte_Ptr )
                        return false;
                    // drop through
                case Int_Types:
                    switch ( ptrtype )
                    {
                        case Byte_Ptr: type_suffix = 'b'; break;
                        case Short_Ptr: type_suffix = 'w'; break;
                        case Int_Ptr: type_suffix = 'l'; break;
                        case QWord_Ptr: type_suffix = 'q'; break;
                        default:
                            // %% these may be too strict
                            return false;
                    }
                    break;
                case FPInt_Types:
                    switch ( ptrtype )
                    {
                        case Short_Ptr: type_suffix = ""; break;
                        case Int_Ptr: type_suffix = 'l'; break;
                        case QWord_Ptr: type_suffix = "ll"; break;
                        default:
                            return false;
                    }
                    break;
                case FP_Types:
                    switch ( ptrtype )
                    {
                        case Float_Ptr: type_suffix = 's'; break;
                        case Double_Ptr: type_suffix = 'l'; break;
                        case Extended_Ptr: type_suffix = 't'; break;
                        default:
                            return false;
                    }
                    break;
                default:
                    return false;
            }
            return true;
        }

        // also set impl clobbers
        bool formatInstruction ( int nOperands, AsmCode * asmcode )
        {
            const char *fmt;
            const char *mnemonic;
            std::string type_suffix;
            bool use_star;
            AsmArgMode mode;

            insnTemplate.str("");
            // %% todo: special case for something..
            if ( opInfo->linkType == Out_Mnemonic )
                mnemonic = alternateMnemonics[opInfo->link];
            else
                mnemonic = opIdent->string;

            // handle two-operand form where second arg is ignored.
            // must be done before type_suffix detection
            if ( op == Op_FidR_P || op == Op_fxch || op == Op_FfdRR_P )
            {
                if (operands[1].cls == Opr_Reg && operands[1].reg == Reg_ST )
                    nOperands = 1;
                else
                    stmt->error("instruction allows only ST as second argument");
            }

            if ( op == Op_FCmpFlgP )
            {
                // Explicitly add %st as second argument to fucomip – it should
                // be implicit, but the GNU as shipping with Mac OS X (Apple Inc
                // version cctools-800~26, GNU assembler version 1.38) chokes on
                // it otherwise.
                assert ( nOperands == 1 );
                nOperands = 2;
                operands[1] = operands[0];
                memset ( operands, 0, sizeof( Operand ) );
                operands[0].cls = Opr_Reg;
                operands[0].reg = Reg_ST;
            }

            if ( opInfo->needsType )
            {
                PtrType exact_type = Default_Ptr;
                PtrType min_type = Default_Ptr;
                PtrType hint_type = Default_Ptr;

                /* Default types: This attempts to match the observed behavior of DMD */
                switch ( opInfo->needsType )
                {
                    case Int_Types: min_type = Byte_Ptr; break;
                    case Word_Types: min_type = Short_Ptr; break;
                    case FPInt_Types:
                        if ( op == Op_Fis_ST ) // integer math instructions
                            min_type = Int_Ptr;
                        else // compare, load, store
                            min_type = Short_Ptr;
                        break;
                    case FP_Types: min_type = Float_Ptr; break;
                }
                if ( op == Op_push && operands[0].cls == Opr_Immediate )
                    min_type = QWord_Ptr;

                for ( int i = 0; i < nOperands; i++ )
                {
                    if ( hint_type == Default_Ptr &&
                            ! ( opInfo->operands[i] & Opr_NoType ) )
                        hint_type = operands[i].dataSizeHint;

                    if ( ( opInfo->operands[i] & Opr_NoType ) ||
                            operands[i].dataSize == Default_Ptr )
                        continue;
                    if ( operands[i].cls == Opr_Immediate )
                    {
                        min_type = operands[i].dataSize > min_type ?
                                   operands[i].dataSize : min_type;
                    }
                    else
                    {
                        exact_type = operands[i].dataSize; // could check for conflicting types
                        break;
                    }
                }

                bool type_ok;
                if ( exact_type == Default_Ptr )
                {
                    type_ok = getTypeSuffix ( ( TypeNeeded ) opInfo->needsType, hint_type, type_suffix );
                    if ( ! type_ok )
                        type_ok = getTypeSuffix ( ( TypeNeeded ) opInfo->needsType, min_type, type_suffix );
                }
                else
                    type_ok = getTypeSuffix ( ( TypeNeeded ) opInfo->needsType, exact_type, type_suffix );

                if ( ! type_ok )
                {
                    stmt->error ( "invalid operand size" );
                    return false;
                }
            }
            else if ( op == Op_Branch )
            {
                if ( operands[0].dataSize == Far_Ptr ) // %% type=Far_Ptr not set by Seg:Ofss OTOH, we don't support that..
                    insnTemplate << 'l';
            }
            else if ( op == Op_FMath0 || op == Op_FdST0ST1 )
            {
                operands[0].cls = Opr_Reg;
                operands[0].reg = Reg_ST1;
                operands[1].cls = Opr_Reg;
                operands[1].reg = Reg_ST;
                nOperands = 2;
            }

            switch ( op )
            {
                case Op_SizedStack:
                {
                    int mlen = strlen ( mnemonic );
                    if ( mnemonic[mlen-1] == 'd' )
                        insnTemplate.write(mnemonic, mlen-1);
                    else
                    {
                        insnTemplate << mnemonic << 'w';
                    }
                }
                break;
                case Op_cmpsd:
                case Op_insX:
                case Op_lodsX:
                case Op_movsd:
                case Op_outsX:
                case Op_scasX:
                case Op_stosX:
                {
                    int mlen = strlen ( mnemonic );
                    if ( mnemonic[mlen-1] == 'd' )
                    {
                        insnTemplate.write(mnemonic, mlen-1) << 'l';
                    }
                    else
                    {
                        insnTemplate << mnemonic;
                    }
                }
                break;
                case Op_movsx:
                case Op_movzx:
                {
                    char tc_1;
                    int mlen = strlen ( mnemonic );
                    PtrType op1_size = operands[1].dataSize;
                    if ( op1_size == Default_Ptr )
                        op1_size = operands[1].dataSizeHint;
                    // Need type char for source arg
                    switch ( op1_size )
                    {
                        case Byte_Ptr:
                        case Default_Ptr:
                            tc_1 = 'b';
                            break;
                        case Short_Ptr:
                            tc_1 = 'w';
                            break;
                        default:
                            stmt->error ( "invalid operand size/type" );
                            return false;
                    }
                    assert ( !type_suffix.empty() );
                    insnTemplate.write(mnemonic, mlen-1) << tc_1 << type_suffix;
                }
                break;

                default:
                // special case fdiv, fsub: see dmd 840, ldc 256
                if ((strncmp(mnemonic, "fsub", 4) == 0 ||
                     strncmp(mnemonic, "fdiv", 4) == 0) &&
                    operands[0].reg != Reg_ST && op != Op_FMath)
                {
                    // replace:
                    // f{sub,div}r{p,} <-> f{sub,div}{p,}
                    if (mnemonic[4] == 'r')
                    {
                        insnTemplate.write(mnemonic, 4);
                        insnTemplate.write(mnemonic+5, strlen(mnemonic)-5);
                    }
                    else
                    {
                        insnTemplate.write(mnemonic, 4) << "r";
                        insnTemplate.write(mnemonic+4, strlen(mnemonic)-4);
                    }
                }
                else
                {
                    insnTemplate << mnemonic;
                }
                // the no-operand versions of floating point ops always pop
                if (op == Op_FMath0)
                    insnTemplate << "p";
                insnTemplate << type_suffix;
                break;
            }

            switch ( opInfo->implicitClobbers & Clb_DXAX_Mask )
            {
                case Clb_SizeAX:
                case Clb_EAX:
                    asmcode->regs[Reg_EAX] = true;
                    break;
                case Clb_SizeDXAX:
                    asmcode->regs[Reg_EAX] = true;
                    if ( type_suffix != "b" )
                        asmcode->regs[Reg_EDX] = true;
                    break;
case Clb_SizeRDXRAX:
asmcode->regs[Reg_RAX] = true;
asmcode->regs[Reg_RDX] = true;
break;
                default:
                    // nothing
                    break;
            }

            if ( opInfo->implicitClobbers & Clb_DI )
                asmcode->regs[Reg_EDI] = true;
            if ( opInfo->implicitClobbers & Clb_SI )
                asmcode->regs[Reg_ESI] = true;
            if ( opInfo->implicitClobbers & Clb_CX )
                asmcode->regs[Reg_ECX] = true;
            if ( opInfo->implicitClobbers & Clb_SP )
                asmcode->regs[Reg_ESP] = true;
            if ( opInfo->implicitClobbers & Clb_ST )
            {
                /* Can't figure out how to tell GCC that an
asm statement leaves an arg pushed on the stack.
Maybe if the statment had and input or output
operand it would work... In any case, clobbering
all FP prevents incorrect code generation. */
                asmcode->regs[Reg_ST] = true;
                asmcode->regs[Reg_ST1] = true;
                asmcode->regs[Reg_ST2] = true;
                asmcode->regs[Reg_ST3] = true;
                asmcode->regs[Reg_ST4] = true;
                asmcode->regs[Reg_ST5] = true;
                asmcode->regs[Reg_ST6] = true;
                asmcode->regs[Reg_ST7] = true;
            }
            if ( opInfo->implicitClobbers & Clb_Flags )
                asmcode->regs[Reg_EFLAGS] = true;
            if ( op == Op_cpuid )
            {
                asmcode->regs[Reg_EAX] = true;
                asmcode->regs[Reg_EBX] = true;
                asmcode->regs[Reg_ECX] = true;
                asmcode->regs[Reg_EDX] = true;
            }

            insnTemplate << ' ';
            for ( int i__ = 0; i__ < nOperands; i__++ )
            {
                int i;
                if ( i__ != 0 )
                    insnTemplate << ", ";

                fmt = "$";

                switch ( op )
                {
                    case Op_mul:
                        // gas won't accept the two-operand form; skip to the source operand
                        i__ = 1;
                        // drop through
                    case Op_bound:
                    case Op_enter:
                        i = i__;
                        break;
                    default:
                        i = nOperands - 1 - i__; // operand = & operands[ nOperands - 1 - i ];
                        break;
                }
                operand = & operands[ i ];

                switch ( operand->cls )
                {
                    case Opr_Immediate:
                        // for implementing offset:
                        // $var + $7 // fails
                        // $var + 7 // ok
                        // $7 + $var // ok

                        // DMD doesn't seem to allow this
                        /*
if (opInfo->takesLabel()) tho... (near ptr <Number> would be abs?)
fmt = "$a"; // GAS won't accept "jmp $42"; must be "jmp 42" (rel) or "jmp *42" (abs)
*/
                        if ( opTakesLabel() /*opInfo->takesLabel()*/ )
                        {
                            // "relative addressing not allowed in branch instructions" ..
                            stmt->error ( "integer constant not allowed in branch instructions" );
                            return false;
                        }

                        if ( operand->symbolDisplacement.dim &&
                                isLocalSize ( ( Expression * ) operand->symbolDisplacement.data[0] ) )
                        {
                            // handle __LOCAL_SIZE, which in this constant, is an immediate
                            // should do this in slotexp..
                            addOperand ( "$", Arg_LocalSize,
                                         ( Expression * ) operand->symbolDisplacement.data[0], asmcode );
                            if ( operand->constDisplacement )
                                insnTemplate << '+';
                            else
                                break;
                        }

                        if ( operand->symbolDisplacement.dim )
                        {
                            fmt = "$a";
                            addOperand ( "$", Arg_Pointer,
                                         ( Expression * ) operand->symbolDisplacement.data[0],
                                         asmcode );

                            if ( operand->constDisplacement )
                                insnTemplate << '+';
                            else
                                // skip the addOperand(fmt, Arg_Integer...) below
                                break;
                        }
                        addOperand ( fmt, Arg_Integer, newIntExp ( operand->constDisplacement ), asmcode );
                        break;
                    case Opr_Reg:
                        if ( opInfo->operands[i] & Opr_Dest )
                        {
                            Reg clbr_reg = ( Reg ) regInfo[operand->reg].baseReg;
                            if ( clbr_reg != Reg_Invalid )
                            {
                                asmcode->regs[clbr_reg] = true;
                            }
                        }
                        if ( opTakesLabel() /*opInfo->takesLabel()*/ )
                            insnTemplate << '*';
                        writeReg ( operand->reg );
                        /*
insnTemplate << "%";
insnTemplate << regInfo[operand->reg].name;
*/
                        break;
                    case Opr_Mem:
                        // better: use output operands for simple variable references
                        if ( ( opInfo->operands[i] & Opr_Update ) == Opr_Update )
                        {
                            mode = Mode_Update;
                        }
                        else if ( opInfo->operands[i] & Opr_Dest )
                        {
                            mode = Mode_Output;
                        }
                        else
                        {
                            mode = Mode_Input;
                        }

                        use_star = opTakesLabel();//opInfo->takesLabel();

                        if (Logger::enabled()) {
                            Logger::cout() << "Opr_Mem\n";
                            LOG_SCOPE
                            Logger::cout() << "baseReg: " << operand->baseReg << '\n';
                            Logger::cout() << "segmentPrefix: " << operand->segmentPrefix << '\n';
                            Logger::cout() << "constDisplacement: " << operand->constDisplacement << '\n';
                            for (unsigned i = 0; i < operand->symbolDisplacement.dim; i++) {
                                Expression* expr = static_cast<Expression*>(operand->symbolDisplacement.data[i]);
                                Logger::cout() << "symbolDisplacement[" << i << "] = " << expr->toChars() << '\n';
                            }
                        }
                        if ( operand->segmentPrefix != Reg_Invalid )
                        {
                            writeReg ( operand->segmentPrefix );
                            insnTemplate << ':';
                        }
                        if ( (operand->segmentPrefix != Reg_Invalid && operand->symbolDisplacement.dim == 0)
                            || operand->constDisplacement )
                        {
                            insnTemplate << operand->constDisplacement;
                            if ( operand->symbolDisplacement.dim )
                            {
                                insnTemplate << '+';
                            }
                            operand->constDisplacement = 0;
                            //addOperand(fmt, Arg_Integer, newIntExp(operand->constDisplacement), asmcode);
                            if ( opInfo->operands[i] & Opr_Dest )
                                asmcode->clobbersMemory = 1;
                        }
                        if ( operand->symbolDisplacement.dim )
                        {
                            Expression * e = ( Expression * ) operand->symbolDisplacement.data[0];
                            Declaration * decl = 0;

                            if ( e->op == TOKvar )
                                decl = ( ( VarExp * ) e )->var;

                            if ( operand->baseReg != Reg_Invalid &&
                                    decl && ! decl->isDataseg() )
                            {

                                // Use the offset from frame pointer

                                /* GCC doesn't give the front end access to stack offsets
when optimization is turned on (3.x) or at all (4.x).

Try to convert var[EBP] (or var[ESP] for naked funcs) to
a memory expression that does not require us to know
the stack offset.
*/

                                if ( operand->indexReg == Reg_Invalid &&
                                        decl->isVarDeclaration() &&
                                        ( ( ( operand->baseReg == Reg_EBP || ( operand->baseReg == Reg_RBP ) ) && ! sc->func->naked ) ||
                                          ( ( operand->baseReg == Reg_ESP || ( operand->baseReg == Reg_RSP ) ) && ! sc->func->naked ) ) )
                                {

                                    e = new AddrExp ( 0, e );
                                    e->type = decl->type->pointerTo();

#if !IN_LLVM
                                    /* DMD uses the same frame offsets for naked functions. */
                                    if ( sc->func->naked )
                                        operand->constDisplacement += 4;

                                    if ( operand->constDisplacement )
                                    {
                                        e = new AddExp ( 0, e,
                                                         new IntegerExp ( 0, operand->constDisplacement,
                                                                          Type::tint64 ) );
                                        e->type = decl->type->pointerTo();
                                    }
                                    e = new PtrExp ( 0, e );
                                    e->type = decl->type;
#endif
                                    operand->constDisplacement = 0;
                                    operand->baseReg = Reg_Invalid;

                                    addOperand ( fmt, Arg_Memory, e, asmcode, mode );

                                }
                                else
                                {
                                    // FIXME: what is this ?
                                    addOperand2 ( "${",":a}", Arg_FrameRelative, e, asmcode );
                                }
                                if ( opInfo->operands[i] & Opr_Dest )
                                    asmcode->clobbersMemory = 1;
                            }
                            else
                            {
                                // Plain memory reference to variable

                                /* If in a reg, DMD moves to memory.. even with -O, so we'll do the same
by always using the "m" contraint.

In order to get the correct output for function and label symbols,
the %an format must be used with the "p" constraint.
*/
                                if ( isDollar ( e ) )
                                {
                                    stmt->error("dollar labels are not supported");
                                    asmcode->dollarLabel = 1;
                                }
                                else if ( e->op == TOKdsymbol )
                                {
                                    LabelDsymbol * lbl = ( LabelDsymbol * ) ( ( DsymbolExp * ) e )->s;
                                    stmt->isBranchToLabel = lbl->ident;

                                    use_star = false;
                                    addLabel ( lbl->ident->toChars() );
                                }
                                else if ( ( decl && decl->isCodeseg() ) ) // if function or label
                                {
                                    use_star = false;
                                    // simply write out the mangle
                                    // on osx and windows, prepend extra _
                                    if ( global.params.os == OSMacOSX || global.params.os == OSWindows )
                                        insnTemplate << "_";
                                    insnTemplate << decl->mangle();
// addOperand2("${", ":c}", Arg_Pointer, e, asmcode);
                                }
                                else
                                {
                                    if ( use_star )
                                    {
                                        insnTemplate << '*';
                                        use_star = false;
                                    }

                                    if ( !sc->func->naked ) // no addrexp in naked asm please :)
                                    {
                                        Type* tt = e->type->pointerTo();
                                        e = new AddrExp ( 0, e );
                                        e->type = tt;
                                    }

                                    addOperand ( fmt, Arg_Memory, e, asmcode, mode );
                                }
                            }
                        }
                        if ( use_star )
                            insnTemplate << '*';
                        if ( operand->baseReg != Reg_Invalid || operand->indexReg != Reg_Invalid )
                        {
                            insnTemplate << '(';
                            if ( operand->baseReg != Reg_Invalid )
                                writeReg ( operand->baseReg );
                            if ( operand->indexReg != Reg_Invalid )
                            {
                                insnTemplate << ',';
                                writeReg ( operand->indexReg );
                                if ( operand->scale )
                                {
                                    insnTemplate << "," << operand->scale;
                                }
                            }
                            insnTemplate << ')';
                            if ( opInfo->operands[i] & Opr_Dest )
                                asmcode->clobbersMemory = 1;
                        }
                        break;
                    case Opr_Invalid:
                        return false;
                }
            }

            asmcode->insnTemplate = insnTemplate.str();
            Logger::cout() << "insnTemplate = " << asmcode->insnTemplate << '\n';
            return true;
        }

        bool isIntExp ( Expression * exp )
        {
            if ( exp->op == TOKint64 )
                return 1;
            if ( exp->op == TOKvar )
            {
                Declaration * v = ( ( VarExp * ) exp )->var;
                if ( v->isConst() && v->type->isintegral() )
                    return 1;
            }
            return 0;
        }
        bool isRegExp ( Expression * exp ) { return exp->op == TOKmod; } // ewww.%%
        bool isLocalSize ( Expression * exp )
        {
            // cleanup: make a static var
            return exp->op == TOKidentifier && ( ( IdentifierExp * ) exp )->ident == Id::__LOCAL_SIZE;
        }
        bool isDollar ( Expression * exp )
        {
            return exp->op == TOKidentifier && ( ( IdentifierExp * ) exp )->ident == Id::__dollar;
        }

        Expression * newRegExp ( int regno )
        {
            IntegerExp * e = new IntegerExp ( regno );
            e->op = TOKmod;
            return e;
        }

        Expression * newIntExp ( long v /* %% type */ )
        {
            // Handle 64 bit ... incoming long may need to be 'long long' for Windows???
            return new IntegerExp ( stmt->loc, v, Type::tint64 );
        }

        void slotExp ( Expression * exp )
        {
            /*
if offset, make a note

if integer, add to immediate
if reg:
if not in bracket, set reg (else error)
if in bracket:
if not base, set base
if not index, set index
else, error
if symbol:
set symbol field
*/

            bool is_offset = false;
            if ( exp->op == TOKaddress )
            {
                exp = ( ( AddrExp * ) exp )->e1;
                is_offset = true;
            }

            if ( isIntExp ( exp ) )
            {
                if ( is_offset )
                    invalidExpression();
                operand->constDisplacement += exp->toInteger();
                if ( ! operand->inBracket )
                    operand->hasNumber = 1;
            }
            else if ( isRegExp ( exp ) )
            {
                if ( is_offset )
                    invalidExpression();
                if ( ! operand->inBracket )
                {
                    if ( operand->reg == Reg_Invalid )
                        operand->reg = ( Reg ) exp->toInteger();
                    else
                        stmt->error ( "too many registers in operand (use brackets)" );
                }
                else
                {
                    if ( operand->baseReg == Reg_Invalid )
                        operand->baseReg = ( Reg ) exp->toInteger();
                    else if ( operand->indexReg == Reg_Invalid )
                    {
                        operand->indexReg = ( Reg ) exp->toInteger();
                        operand->scale = 1;
                    }
                    else
                    {
                        stmt->error ( "too many registers memory operand" );
                    }
                }
            }
            else if ( exp->op == TOKvar )
            {
                VarDeclaration * v = ( ( VarExp * ) exp )->var->isVarDeclaration();

                if ( v && v->storage_class & STCfield )
                {
                    operand->constDisplacement += v->offset;
                    if ( ! operand->inBracket )
                        operand->hasNumber = 1;
                }
                else
                {
                    if ( v && v->type->isscalar() )
                    {
                        // DMD doesn't check Tcomplex*, and counts Tcomplex32 as Tfloat64
                        TY ty = v->type->toBasetype()->ty;
                        operand->dataSizeHint = ty == Tfloat80 || ty == Timaginary80 ?
                                                Extended_Ptr : ( PtrType ) v->type->size ( 0 );
                    }

                    if ( ! operand->symbolDisplacement.dim )
                    {
                        if ( is_offset && ! operand->inBracket )
                            operand->isOffset = 1;
                        operand->symbolDisplacement.push ( exp );
                    }
                    else
                    {
                        stmt->error ( "too many symbols in operand" );
                    }
                }
            }
            else if ( exp->op == TOKidentifier || exp->op == TOKdsymbol )
            {
                // %% localsize could be treated as a simple constant..
                // change to addSymbolDisp(e)
                if ( ! operand->symbolDisplacement.dim )
                {
                    operand->symbolDisplacement.push ( exp );
                }
                else
                {
                    stmt->error ( "too many symbols in operand" );
                }
            }
            else if ( exp == Handled )
            {
                // nothing
            }
            else
            {
                stmt->error ( "invalid operand" );
            }
        }

        void invalidExpression()
        {
            // %% report operand number
            stmt->error ( "invalid expression" );
        }

        Expression * intOp ( TOK op, Expression * e1, Expression * e2 )
        {
            Expression * e;
            if ( isIntExp ( e1 ) && ( ! e2 || isIntExp ( e2 ) ) )
            {
                switch ( op )
                {
                    case TOKadd:
                        if ( e2 )
                            e = new AddExp ( stmt->loc, e1, e2 );
                        else
                            e = e1;
                        break;
                    case TOKmin:
                        if ( e2 )
                            e = new MinExp ( stmt->loc, e1, e2 );
                        else
                            e = new NegExp ( stmt->loc, e1 );
                        break;
                    case TOKmul:
                        e = new MulExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKdiv:
                        e = new DivExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKmod:
                        e = new ModExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKshl:
                        e = new ShlExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKshr:
                        e = new ShrExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKushr:
                        e = new UshrExp ( stmt->loc, e1, e2 );
                        break;
                    case TOKnot:
                        e = new NotExp ( stmt->loc, e1 );
                        break;
                    case TOKtilde:
                        e = new ComExp ( stmt->loc, e1 );
                        break;
                    default:
                        assert ( 0 );
                }
                e = e->semantic ( sc );
                return e->optimize ( WANTvalue | WANTinterpret );
            }
            else
            {
                stmt->error ( "expected integer operand(s) for '%s'", Token::tochars[op] );
                return newIntExp ( 0 );
            }
        }

        void parseOperand()
        {
            Expression * exp = parseAsmExp();
            slotExp ( exp );
            if ( isRegExp ( exp ) )
                operand->dataSize = ( PtrType ) regInfo[exp->toInteger() ].size;
        }

        Expression * parseAsmExp()
        {
            return parseShiftExp();
        }

        Expression * parseShiftExp()
        {
            Expression * e1 = parseAddExp();
            Expression * e2;

            while ( 1 )
            {
                TOK tv = token->value;
                switch ( tv )
                {
                    case TOKshl:
                    case TOKshr:
                    case TOKushr:
                        nextToken();
                        e2 = parseAddExp();
                        e1 = intOp ( tv, e1, e2 );
                        continue;
                    default:
                        break;
                }
                break;
            }
            return e1;
        }

        Expression * parseAddExp()
        {
            Expression * e1 = parseMultExp();
            Expression * e2;

            while ( 1 )
            {
                TOK tv = token->value;
                switch ( tv )
                {
                    case TOKadd:
                        nextToken();
                        e2 = parseMultExp();
                        if ( isIntExp ( e1 ) && isIntExp ( e2 ) )
                            e1 = intOp ( tv, e1, e2 );
                        else
                        {
                            slotExp ( e1 );
                            slotExp ( e2 );
                            e1 = Handled;
                        }
                        continue;
                    case TOKmin:
                        // Note: no support for symbol address difference
                        nextToken();
                        e2 = parseMultExp();
                        if ( isIntExp ( e1 ) && isIntExp ( e2 ) )
                            e1 = intOp ( tv, e1, e2 );
                        else
                        {
                            slotExp ( e1 );
                            e2 = intOp ( TOKmin, e2, NULL ); // verifies e2 is an int
                            slotExp ( e2 );
                            e1 = Handled;
                        }
                        continue;
                    default:
                        break;
                }
                break;
            }
            return e1;
        }

        bool tryScale ( Expression * e1, Expression * e2 )
        {
            Expression * et;
            if ( isIntExp ( e1 ) && isRegExp ( e2 ) )
            {
                et = e1;
                e1 = e2;
                e2 = et;
                goto do_scale;
            }
            else if ( isRegExp ( e1 ) && isIntExp ( e2 ) )
            {
            do_scale:
                if ( ! operand->inBracket )
                {
                    invalidExpression(); // maybe should allow, e.g. DS:EBX+EAX*4
                }

                if ( operand->scale || operand->indexReg != Reg_Invalid )
                {
                    invalidExpression();
                    return true;
                }

                operand->indexReg = ( Reg ) e1->toInteger();
                operand->scale = e2->toInteger();
                switch ( operand->scale )
                {
                    case 1:
                    case 2:
                    case 4:
                    case 8:
                        // ok; do nothing
                        break;
                    default:
                        stmt->error ( "invalid index register scale '%d'", operand->scale );
                        return true;
                }

                return true;
            }
            return false;
        }

        Expression * parseMultExp()
        {
            Expression * e1 = parseBrExp();
            Expression * e2;

            while ( 1 )
            {
                TOK tv = token->value;
                switch ( tv )
                {
                    case TOKmul:
                        nextToken();
                        e2 = parseMultExp();
                        if ( isIntExp ( e1 ) && isIntExp ( e2 ) )
                            e1 = intOp ( tv, e1, e2 );
                        else if ( tryScale ( e1,e2 ) )
                            e1 = Handled;
                        else
                            invalidExpression();
                        continue;
                    case TOKdiv:
                    case TOKmod:
                        nextToken();
                        e2 = parseMultExp();
                        e1 = intOp ( tv, e1, e2 );
                        continue;
                    default:
                        break;
                }
                break;
            }
            return e1;
        }

        Expression * parseBrExp()
        {
            // %% check (why is bracket lower precends..)
            // 3+4[eax] -> 3 + (4 [EAX]) ..

            // only one bracked allowed, so this doesn't quite handle
            // the spec'd syntax
            Expression * e;

            if ( token->value == TOKlbracket )
                e = Handled;
            else
                e = parseUnaExp();

            // DMD allows multiple bracket expressions.
            while ( token->value == TOKlbracket )
            {
                nextToken();

                operand->inBracket = operand->hasBracket = 1;
                slotExp ( parseAsmExp() );
                operand->inBracket = 0;

                if ( token->value == TOKrbracket )
                    nextToken();
                else
                    stmt->error ( "missing ']'" );
            }

            return e;
        }

        PtrType isPtrType ( Token * tok )
        {
            switch ( tok->value )
            {
                case TOKint8: return Byte_Ptr;
                case TOKint16: return Short_Ptr;
                case TOKint32: return Int_Ptr;
                case TOKint64: return QWord_Ptr;
                    // 'long ptr' isn't accepted? (it is now for x64 - qword)
                case TOKfloat32: return Float_Ptr;
                case TOKfloat64: return Double_Ptr;
                case TOKfloat80: return Extended_Ptr;
                case TOKidentifier:
                    for ( int i = 0; i < N_PtrNames; i++ )
                        if ( tok->ident == ptrTypeIdentTable[i] )
                            return ptrTypeValueTable[i];
                    break;
                default:
                    break;
            }
            return Default_Ptr;
        }

        Expression * parseUnaExp()
        {
            Expression * e = NULL;
            PtrType ptr_type;

            // First, check for type prefix.
            if ( token->value != TOKeof &&
                    peekToken()->value == TOKidentifier &&
                    peekToken()->ident == Id::ptr )
            {

                ptr_type = isPtrType ( token );
                if ( ptr_type != Default_Ptr )
                {
                    if ( operand->dataSize == Default_Ptr )
                        operand->dataSize = ptr_type;
                    else
                        stmt->error ( "multiple specifications of operand size" );
                }
                else
                    stmt->error ( "unknown operand size '%s'", token->toChars() );
                nextToken();
                nextToken();
                return parseAsmExp();
            }

            TOK tv = token->value;
            switch ( tv )
            {
                case TOKidentifier:
                    if ( token->ident == ident_seg )
                    {
                        nextToken();
                        stmt->error ( "'seg' not supported" );
                        e = parseAsmExp();
                    }
                    else if ( token->ident == Id::offset ||
                              token->ident == Id::offsetof )
                    {
                        if ( token->ident == Id::offset && ! global.params.useDeprecated )
                            stmt->error ( "offset deprecated, use offsetof" );
                        nextToken();
                        e = parseAsmExp();
                        e = new AddrExp ( stmt->loc, e );
                    }
                    else
                    {
                        // primary exp
                        break;
                    }
                    return e;
                case TOKadd:
                case TOKmin:
                case TOKnot:
                case TOKtilde:
                    nextToken();
                    e = parseUnaExp();
                    return intOp ( tv, e, NULL );
                default:
                    // primary exp
                    break;
            }
            return parsePrimaryExp();
        }

        Expression * parsePrimaryExp()
        {
            Expression * e;
            Identifier * ident = NULL;

            // get rid of short/long prefixes for branches
            if (opTakesLabel() && (token->value == TOKint16 || token->value == TOKint64))
                nextToken();

            switch ( token->value )
            {
                case TOKint32v:
                case TOKuns32v:
                case TOKint64v:
                case TOKuns64v:
                    // semantic here?
                    // %% for tok64 really should use 64bit type
                    e = new IntegerExp ( stmt->loc, token->uns64value, Type::tint64 );
                    nextToken();
                    break;
                case TOKfloat32v:
                case TOKfloat64v:
                case TOKfloat80v:
                    // %% need different types?
                    e = new RealExp ( stmt->loc, token->float80value, Type::tfloat80 );
                    nextToken();
                    break;
                case TOKidentifier:
                {
                    ident = token->ident;
                    nextToken();

                    if ( ident == Id::__LOCAL_SIZE )
                    {
                        return new IdentifierExp ( stmt->loc, ident );
                    }
                    else if ( ident == Id::__dollar )
                    {
                    do_dollar:
                        return new IdentifierExp ( stmt->loc, ident );
                    }
                    else
                    {
                        e = new IdentifierExp ( stmt->loc, ident );
                    }

                    // If this is more than one component ref, it gets complicated: *(&Field + n)
                    // maybe just do one step at a time..
                    // simple case is Type.f -> VarDecl(field)
                    // actually, DMD only supports on level...
                    // X.y+Y.z[EBX] is supported, tho..
                    // %% doesn't handle properties (check%%)
                    while ( token->value == TOKdot )
                    {
                        nextToken();
                        if ( token->value == TOKidentifier )
                        {
                            e = new DotIdExp ( stmt->loc, e, token->ident );
                            nextToken();
                        }
                        else
                        {
                            stmt->error ( "expected identifier" );
                            return Handled;
                        }
                    }

                    // check for reg first then dotexp is an error?
                    if ( e->op == TOKidentifier )
                    {
                        for ( int i = 0; i < N_Regs; i++ )
                        {
                            if ( ident == regInfo[i].ident )
                            {
                                if ( ( Reg ) i == Reg_ST && token->value == TOKlparen )
                                {
                                    nextToken();
                                    switch ( token->value )
                                    {
                                    case TOKint32v: case TOKuns32v:
                                    case TOKint64v: case TOKuns64v:
                                            if ( token->uns64value < 8 )
                                                e = newRegExp ( ( Reg ) ( Reg_ST + token->uns64value ) );
                                            else
                                            {
                                                stmt->error ( "invalid floating point register index" );
                                                e = Handled;
                                            }
                                            nextToken();
                                            if ( token->value == TOKrparen )
                                                nextToken();
                                            else
                                                stmt->error ( "expected ')'" );
                                            return e;
                                        default:
                                            break;
                                    }
                                    invalidExpression();
                                    return Handled;
                                }
                                else if ( token->value == TOKcolon )
                                {
                                    nextToken();
                                    if ( operand->segmentPrefix != Reg_Invalid )
                                        stmt->error ( "too many segment prefixes" );
                                    else if ( i >= Reg_CS && i <= Reg_GS )
                                        operand->segmentPrefix = ( Reg ) i;
                                    else
                                        stmt->error ( "'%s' is not a segment register", ident->string );
                                    return parseAsmExp();
                                }
                                else
                                {
                                    return newRegExp ( ( Reg ) i );
                                }
                            }
                        }
                    }

                    if ( opTakesLabel() /*opInfo->takesLabel()*/ && e->op == TOKidentifier )
                    {
                        // DMD uses labels secondarily to other symbols, so check
                        // if IdentifierExp::semantic won't find anything.
                        Dsymbol *scopesym;

                        if ( ! sc->search ( stmt->loc, ident, & scopesym ) )
                            return new DsymbolExp ( stmt->loc,
                                                    sc->func->searchLabel ( ident ) );
                    }

                    e = e->semantic ( sc );

                    // Special case for floating point constant declarations.
                    if ( e->op == TOKfloat64 )
                    {
                        Dsymbol * sym = sc->search ( stmt->loc, ident, NULL );
                        if ( sym )
                        {
                            VarDeclaration *v = sym->isVarDeclaration();
                            if ( v )
                            {
                                Expression *ve = new VarExp ( stmt->loc, v );
                                ve->type = e->type;
                                e = ve;
                            }
                        }
                    }
                    return e;
                }
                break;
                case TOKdollar:
                    nextToken();
                    ident = Id::__dollar;
                    goto do_dollar;
                    break;
                default:
                    if ( op == Op_FMath0 || op == Op_FdST0ST1 || op == Op_FMath )
                        return Handled;
                    invalidExpression();
                    return Handled;
            }
            return e;
        }

        void doAlign()
        {
            // .align bits vs. bytes...
            // apparently a.out platforms use bits instead of bytes...

            // parse primary: DMD allows 'MyAlign' (const int) but not '2+2'
            // GAS is padding with NOPs last time I checked.
            Expression * e = parseAsmExp()->optimize ( WANTvalue | WANTinterpret );
            uinteger_t align = e->toUInteger();

            if ( ( align & ( align - 1 ) ) == 0 )
            {
                //FIXME: This printf is not portable. The use of `align` varies from system to system;
                // on i386 using a.out, .align `n` will align on a 2^`n` boundary instead of an `n` boundary
#ifdef HAVE_GAS_BALIGN_AND_P2ALIGN
                insnTemplate << ".balign\t" << align;
#else
                insnTemplate << ".align\t" << align;
#endif
            }
            else
            {
                stmt->error ( "alignment must be a power of 2, not %u", ( unsigned ) align );
            }

            setAsmCode();
        }

        void doEven()
        {
            // .align for GAS is in bits, others probably use bytes..
#ifdef HAVE_GAS_BALIGN_AND_P2ALIGN
            insnTemplate << ".align\t2";
#else
            insnTemplate << ".align\t2";
#endif
            setAsmCode();
        }

        void doNaked()
        {
            // %% can we assume sc->func != 0?
            sc->func->naked = 1;
        }

        void doData()
        {
            static const char * directives[] = { ".byte", ".short", ".long", ".long",
                                                 "", "", ""
                                               };
// FIXME
            /*
machine_mode mode;

insnTemplate->writestring(static_cast<char*>(directives[op - Op_db]));
insnTemplate->writebyte(' ');

do {
// DMD is pretty strict here, not even constant expressions are allowed..
switch (op) {
case Op_db:
case Op_ds:
case Op_di:
case Op_dl:
if (token->value == TOKint32v || token->value == TOKuns32v ||
token->value == TOKint64v || token->value == TOKuns64v) {
// As per usual with GNU, assume at least 32-bit host
if (op != Op_dl)
insnTemplate->printf("%u", (d_uns32) token->uns64value);
else {
// Output two .longS. GAS has .quad, but would have to rely on 'L' format ..
// just need to use HOST_WIDE_INT_PRINT_DEC
insnTemplate->printf("%u,%u",
(d_uns32) token->uns64value, (d_uns32) (token->uns64value >> 32));
}
} else {
stmt->error("expected integer constant");
}
break;
case Op_df:
mode = SFmode;
goto do_float;
case Op_dd:
mode = DFmode;
goto do_float;
case Op_de:
#ifndef TARGET_80387
#define XFmode TFmode
#endif
mode = XFmode; // not TFmode
// drop through
do_float:
if (token->value == TOKfloat32v || token->value == TOKfloat64v ||
token->value == TOKfloat80v) {
long words[3];
real_to_target(words, & token->float80value.rv(), mode);
// don't use directives..., just use .long like GCC
insnTemplate->printf(".long\t%u", words[0]);
if (mode != SFmode)
insnTemplate->printf(",%u", words[1]);
// DMD outputs 10 bytes, so we need to switch to .short here
if (mode == XFmode)
insnTemplate->printf("\n\t.short\t%u", words[2]);
} else {
stmt->error("expected float constant");
}
break;
default:
abort();
}

nextToken();
if (token->value == TOKcomma) {
insnTemplate->writebyte(',');
nextToken();
} else if (token->value == TOKeof) {
break;
} else {
stmt->error("expected comma");
}
} while (1);

setAsmCode();*/
        }
    };

#if D_GCC_VER < 40
// struct rtx was modified for c++; this macro from rtl.h needs to
// be modified accordingly.
#undef XEXP
#define XEXP(RTX, N) (RTL_CHECK2 (RTX, N, 'e', 'u').rt_rtx)
#endif

// FIXME
#define HOST_WIDE_INT long
    bool getFrameRelativeValue ( LLValue* decl, HOST_WIDE_INT * result )
    {
        assert ( 0 );
// FIXME
// // Using this instead of DECL_RTL for struct args seems like a
// // good way to get hit by a truck because it may not agree with
// // non-asm access, but asm code wouldn't know what GCC does anyway. */
// rtx r = DECL_INCOMING_RTL(decl);
// rtx e1, e2;
//
// // Local variables don't have DECL_INCOMING_RTL
// if (r == NULL_RTX)
// r = DECL_RTL(decl);
//
// if (r != NULL_RTX && GET_CODE(r) == MEM /* && r->frame_related */ ) {
// r = XEXP(r, 0);
// if (GET_CODE(r) == PLUS) {
// e1 = XEXP(r, 0);
// e2 = XEXP(r, 1);
// if (e1 == virtual_incoming_args_rtx && GET_CODE(e2) == CONST_INT) {
// *result = INTVAL(e2) + 8; // %% 8 is 32-bit specific...
// return true;
// } else if (e1 == virtual_stack_vars_rtx && GET_CODE(e2) == CONST_INT) {
// *result = INTVAL(e2); // %% 8 is 32-bit specific...
// return true;
// }
// } else if (r == virtual_incoming_args_rtx) {
// *result = 8;
// return true; // %% same as above
// }
// // shouldn't have virtual_stack_vars_rtx by itself
// }
//
        return false;
    }


    struct AsmParser : public AsmParserCommon
    {
        virtual void run ( Scope* sc, AsmStatement* asmst )
        {
            AsmProcessor ap ( sc, asmst );
            ap.run();
        }

        virtual std::string getRegName ( int i )
        {
            return regInfo[i].gccName;
        }
    };

}
Something went wrong with that request. Please try again.