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
|
/* SPIM S20 MIPS simulator.
Parser for instructions and assembler directives.
Copyright (c) 1990-2010, James R. Larus.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the James R. Larus nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
%start LINE
%token Y_EOF
%token Y_NL
%token Y_INT
%token Y_ID
%token Y_REG
%token Y_FP_REG
%token Y_STR
%token Y_FP
/* MIPS instructions op codes: */
%token Y_ABS_D_OP
%token Y_ABS_PS_OP
%token Y_ABS_S_OP
%token Y_ADD_D_OP
%token Y_ADD_OP
%token Y_ADD_PS_OP
%token Y_ADD_S_OP
%token Y_ADDI_OP
%token Y_ADDIU_OP
%token Y_ADDU_OP
%token Y_ALNV_PS_OP
%token Y_AND_OP
%token Y_ANDI_OP
%token Y_BC1F_OP
%token Y_BC1FL_OP
%token Y_BC1T_OP
%token Y_BC1TL_OP
%token Y_BC2F_OP
%token Y_BC2FL_OP
%token Y_BC2T_OP
%token Y_BC2TL_OP
%token Y_BEQ_OP
%token Y_BEQL_OP
%token Y_BGEZ_OP
%token Y_BGEZAL_OP
%token Y_BGEZALL_OP
%token Y_BGEZL_OP
%token Y_BGTZ_OP
%token Y_BGTZL_OP
%token Y_BLEZ_OP
%token Y_BLEZL_OP
%token Y_BLTZ_OP
%token Y_BLTZAL_OP
%token Y_BLTZALL_OP
%token Y_BLTZL_OP
%token Y_BNE_OP
%token Y_BNEL_OP
%token Y_BREAK_OP
%token Y_C_EQ_D_OP
%token Y_C_EQ_PS_OP
%token Y_C_EQ_S_OP
%token Y_C_F_D_OP
%token Y_C_F_PS_OP
%token Y_C_F_S_OP
%token Y_C_LE_D_OP
%token Y_C_LE_PS_OP
%token Y_C_LE_S_OP
%token Y_C_LT_D_OP
%token Y_C_LT_PS_OP
%token Y_C_LT_S_OP
%token Y_C_NGE_D_OP
%token Y_C_NGE_PS_OP
%token Y_C_NGE_S_OP
%token Y_C_NGL_D_OP
%token Y_C_NGL_PS_OP
%token Y_C_NGL_S_OP
%token Y_C_NGLE_D_OP
%token Y_C_NGLE_PS_OP
%token Y_C_NGLE_S_OP
%token Y_C_NGT_D_OP
%token Y_C_NGT_PS_OP
%token Y_C_NGT_S_OP
%token Y_C_OLE_D_OP
%token Y_C_OLE_PS_OP
%token Y_C_OLE_S_OP
%token Y_C_OLT_D_OP
%token Y_C_OLT_PS_OP
%token Y_C_OLT_S_OP
%token Y_C_SEQ_D_OP
%token Y_C_SEQ_PS_OP
%token Y_C_SEQ_S_OP
%token Y_C_SF_D_OP
%token Y_C_SF_PS_OP
%token Y_C_SF_S_OP
%token Y_C_UEQ_D_OP
%token Y_C_UEQ_PS_OP
%token Y_C_UEQ_S_OP
%token Y_C_ULE_D_OP
%token Y_C_ULE_PS_OP
%token Y_C_ULE_S_OP
%token Y_C_ULT_D_OP
%token Y_C_ULT_PS_OP
%token Y_C_ULT_S_OP
%token Y_C_UN_D_OP
%token Y_C_UN_PS_OP
%token Y_C_UN_S_OP
%token Y_CACHE_OP
%token Y_CEIL_L_D_OP
%token Y_CEIL_L_S_OP
%token Y_CEIL_W_D_OP
%token Y_CEIL_W_S_OP
%token Y_CFC0_OP
%token Y_CFC1_OP
%token Y_CFC2_OP
%token Y_CLO_OP
%token Y_CLZ_OP
%token Y_COP2_OP
%token Y_CTC0_OP
%token Y_CTC1_OP
%token Y_CTC2_OP
%token Y_CVT_D_L_OP
%token Y_CVT_D_S_OP
%token Y_CVT_D_W_OP
%token Y_CVT_L_D_OP
%token Y_CVT_L_S_OP
%token Y_CVT_PS_S_OP
%token Y_CVT_S_D_OP
%token Y_CVT_S_L_OP
%token Y_CVT_S_PL_OP
%token Y_CVT_S_PU_OP
%token Y_CVT_S_W_OP
%token Y_CVT_W_D_OP
%token Y_CVT_W_S_OP
%token Y_DERET_OP
%token Y_DI_OP
%token Y_DIV_D_OP
%token Y_DIV_OP
%token Y_DIV_S_OP
%token Y_DIVU_OP
%token Y_EHB_OP
%token Y_EI_OP
%token Y_ERET_OP
%token Y_EXT_OP
%token Y_FLOOR_L_D_OP
%token Y_FLOOR_L_S_OP
%token Y_FLOOR_W_D_OP
%token Y_FLOOR_W_S_OP
%token Y_INS_OP
%token Y_J_OP
%token Y_JAL_OP
%token Y_JALR_HB_OP
%token Y_JALR_OP
%token Y_JR_HB_OP
%token Y_JR_OP
%token Y_LB_OP
%token Y_LBU_OP
%token Y_LDC1_OP
%token Y_LDC2_OP
%token Y_LDXC1_OP
%token Y_LH_OP
%token Y_LHU_OP
%token Y_LL_OP
%token Y_LUI_OP
%token Y_LUXC1_OP
%token Y_LW_OP
%token Y_LWC1_OP
%token Y_LWC2_OP
%token Y_LWL_OP
%token Y_LWR_OP
%token Y_LWXC1_OP
%token Y_MADD_D_OP
%token Y_MADD_OP
%token Y_MADD_PS_OP
%token Y_MADD_S_OP
%token Y_MADDU_OP
%token Y_MFC0_OP
%token Y_MFC1_OP
%token Y_MFC2_OP
%token Y_MFHC1_OP
%token Y_MFHC2_OP
%token Y_MFHI_OP
%token Y_MFLO_OP
%token Y_MOV_D_OP
%token Y_MOV_PS_OP
%token Y_MOV_S_OP
%token Y_MOVF_D_OP
%token Y_MOVF_OP
%token Y_MOVF_PS_OP
%token Y_MOVF_S_OP
%token Y_MOVN_D_OP
%token Y_MOVN_OP
%token Y_MOVN_PS_OP
%token Y_MOVN_S_OP
%token Y_MOVT_D_OP
%token Y_MOVT_OP
%token Y_MOVT_PS_OP
%token Y_MOVT_S_OP
%token Y_MOVZ_D_OP
%token Y_MOVZ_OP
%token Y_MOVZ_PS_OP
%token Y_MOVZ_S_OP
%token Y_MSUB_D_OP
%token Y_MSUB_OP
%token Y_MSUB_PS_OP
%token Y_MSUB_S_OP
%token Y_MSUBU_OP
%token Y_MTC0_OP
%token Y_MTC1_OP
%token Y_MTC2_OP
%token Y_MTHC1_OP
%token Y_MTHC2_OP
%token Y_MTHI_OP
%token Y_MTLO_OP
%token Y_MUL_D_OP
%token Y_MUL_PS_OP
%token Y_MUL_S_OP
%token Y_MUL_OP
%token Y_MULT_OP
%token Y_MULTU_OP
%token Y_NEG_D_OP
%token Y_NEG_PS_OP
%token Y_NEG_S_OP
%token Y_NMADD_D_OP
%token Y_NMADD_PS_OP
%token Y_NMADD_S_OP
%token Y_NMSUB_D_OP
%token Y_NMSUB_PS_OP
%token Y_NMSUB_S_OP
%token Y_NOR_OP
%token Y_OR_OP
%token Y_ORI_OP
%token Y_PFW_OP
%token Y_PLL_PS_OP
%token Y_PLU_PS_OP
%token Y_PREF_OP
%token Y_PREFX_OP
%token Y_PUL_PS_OP
%token Y_PUU_PS_OP
%token Y_RDHWR_OP
%token Y_RDPGPR_OP
%token Y_RECIP_D_OP
%token Y_RECIP_S_OP
%token Y_RFE_OP
%token Y_ROTR_OP
%token Y_ROTRV_OP
%token Y_ROUND_L_D_OP
%token Y_ROUND_L_S_OP
%token Y_ROUND_W_D_OP
%token Y_ROUND_W_S_OP
%token Y_RSQRT_D_OP
%token Y_RSQRT_S_OP
%token Y_SB_OP
%token Y_SC_OP
%token Y_SDBBP_OP
%token Y_SDC1_OP
%token Y_SDC2_OP
%token Y_SDXC1_OP
%token Y_SEB_OP
%token Y_SEH_OP
%token Y_SH_OP
%token Y_SLL_OP
%token Y_SLLV_OP
%token Y_SLT_OP
%token Y_SLTI_OP
%token Y_SLTIU_OP
%token Y_SLTU_OP
%token Y_SQRT_D_OP
%token Y_SQRT_S_OP
%token Y_SRA_OP
%token Y_SRAV_OP
%token Y_SRL_OP
%token Y_SRLV_OP
%token Y_SSNOP_OP
%token Y_SUB_D_OP
%token Y_SUB_OP
%token Y_SUB_PS_OP
%token Y_SUB_S_OP
%token Y_SUBU_OP
%token Y_SUXC1_OP
%token Y_SW_OP
%token Y_SWC1_OP
%token Y_SWC2_OP
%token Y_SWL_OP
%token Y_SWR_OP
%token Y_SWXC1_OP
%token Y_SYNC_OP
%token Y_SYNCI_OP
%token Y_SYSCALL_OP
%token Y_TEQ_OP
%token Y_TEQI_OP
%token Y_TGE_OP
%token Y_TGEI_OP
%token Y_TGEIU_OP
%token Y_TGEU_OP
%token Y_TLBP_OP
%token Y_TLBR_OP
%token Y_TLBWI_OP
%token Y_TLBWR_OP
%token Y_TLT_OP
%token Y_TLTI_OP
%token Y_TLTIU_OP
%token Y_TLTU_OP
%token Y_TNE_OP
%token Y_TNEI_OP
%token Y_TRUNC_L_D_OP
%token Y_TRUNC_L_S_OP
%token Y_TRUNC_W_D_OP
%token Y_TRUNC_W_S_OP
%token Y_WRPGPR_OP
%token Y_WSBH_OP
%token Y_XOR_OP
%token Y_XORI_OP
/* Assembler pseudo operations op codes: */
%token Y_ABS_POP
%token Y_B_POP
%token Y_BAL_POP
%token Y_BEQZ_POP
%token Y_BGE_POP
%token Y_BGEU_POP
%token Y_BGT_POP
%token Y_BGTU_POP
%token Y_BLE_POP
%token Y_BLEU_POP
%token Y_BLT_POP
%token Y_BLTU_POP
%token Y_BNEZ_POP
%token Y_LA_POP
%token Y_LD_POP
%token Y_L_D_POP
%token Y_L_S_POP
%token Y_LI_D_POP
%token Y_LI_POP
%token Y_LI_S_POP
%token Y_MFC1_D_POP
%token Y_MOVE_POP
%token Y_MTC1_D_POP
%token Y_MULO_POP
%token Y_MULOU_POP
%token Y_NEG_POP
%token Y_NEGU_POP
%token Y_NOP_POP
%token Y_NOT_POP
%token Y_REM_POP
%token Y_REMU_POP
%token Y_ROL_POP
%token Y_ROR_POP
%token Y_S_D_POP
%token Y_S_S_POP
%token Y_SD_POP
%token Y_SEQ_POP
%token Y_SGE_POP
%token Y_SGEU_POP
%token Y_SGT_POP
%token Y_SGTU_POP
%token Y_SLE_POP
%token Y_SLEU_POP
%token Y_SNE_POP
%token Y_ULH_POP
%token Y_ULHU_POP
%token Y_ULW_POP
%token Y_USH_POP
%token Y_USW_POP
/* Assembler directives: */
%token Y_ALIAS_DIR
%token Y_ALIGN_DIR
%token Y_ASCII_DIR
%token Y_ASCIIZ_DIR
%token Y_ASM0_DIR
%token Y_BGNB_DIR
%token Y_BYTE_DIR
%token Y_COMM_DIR
%token Y_DATA_DIR
%token Y_DOUBLE_DIR
%token Y_END_DIR
%token Y_ENDB_DIR
%token Y_ENDR_DIR
%token Y_ENT_DIR
%token Y_ERR_DIR
%token Y_EXTERN_DIR
%token Y_FILE_DIR
%token Y_FLOAT_DIR
%token Y_FMASK_DIR
%token Y_FRAME_DIR
%token Y_GLOBAL_DIR
%token Y_HALF_DIR
%token Y_K_DATA_DIR
%token Y_K_TEXT_DIR
%token Y_LABEL_DIR
%token Y_LCOMM_DIR
%token Y_LIVEREG_DIR
%token Y_LOC_DIR
%token Y_MASK_DIR
%token Y_NOALIAS_DIR
%token Y_OPTIONS_DIR
%token Y_RDATA_DIR
%token Y_REPEAT_DIR
%token Y_SDATA_DIR
%token Y_SET_DIR
%token Y_SPACE_DIR
%token Y_STRUCT_DIR
%token Y_TEXT_DIR
%token Y_VERSTAMP_DIR
%token Y_VREG_DIR
%token Y_WORD_DIR
%{
#include <stdio.h>
#include "spim.h"
#include "string-stream.h"
#include "spim-utils.h"
#include "inst.h"
#include "reg.h"
#include "mem.h"
#include "sym-tbl.h"
#include "data.h"
#include "scanner.h"
#include "parser.h"
/* return (0) */
#define LINE_PARSE_DONE YYACCEPT
/* return (1) */
#define FILE_PARSE_DONE YYABORT
typedef struct ll
{
label *head;
struct ll *tail;
} label_list;
/* Exported Variables: */
int data_dir; /* Non-zero means item in data segment */
int text_dir; /* Non-zero means item in text segment */
int parse_error_occurred; /* Non-zero => parse resulted in error */
/* Local functions: */
static imm_expr *branch_offset (int n_inst);
static int cc_to_rt (int cc, int nd, int tf);
static void check_imm_range (imm_expr*, int32, int32);
static void check_uimm_range (imm_expr*, uint32, uint32);
static void clear_labels ();
static label_list *cons_label (label *head, label_list *tail);
static void div_inst (int op, int rd, int rs, int rt, int const_divisor);
static void mips32_r2_inst ();
static void mult_inst (int op, int rd, int rs, int rt);
static void nop_inst ();
static void set_eq_inst (int op, int rd, int rs, int rt);
static void set_ge_inst (int op, int rd, int rs, int rt);
static void set_gt_inst (int op, int rd, int rs, int rt);
static void set_le_inst (int op, int rd, int rs, int rt);
static void store_word_data (int value);
static void trap_inst ();
static void yywarn (char*);
/* Local variables: */
static int null_term; /* Non-zero means string terminate by \0 */
static void (*store_op) (); /* Function to store items in an EXPR_LST */
static label_list *this_line_labels = NULL; /* List of label for curent line */
static int noat_flag = 0; /* Non-zero means program can use $1 */
static char *input_file_name; /* Name of file being parsed */
%}
%%
LINE: {parse_error_occurred = 0; scanner_start_line (); } LBL_CMD ;
LBL_CMD: OPT_LBL CMD
| CMD
;
OPT_LBL: ID ':' {
/* Call outside of cons_label, since an error sets that variable to NULL. */
label* l = record_label ((char*)$1.p,
text_dir ? current_text_pc () : current_data_pc (),
0);
this_line_labels = cons_label (l, this_line_labels);
free ((char*)$1.p);
}
| ID '=' Y_INT
{
label *l = record_label ((char*)$1.p, (mem_addr)$3.i, 1);
free ((char*)$1.p);
l->const_flag = 1;
clear_labels ();
}
;
CMD: ASM_CODE
{
clear_labels ();
}
TERM
| ASM_DIRECTIVE
{
clear_labels ();
}
TERM
| TERM
;
TERM: Y_NL
{
LINE_PARSE_DONE;
}
| Y_EOF
{
clear_labels ();
FILE_PARSE_DONE;
}
;
ASM_CODE: LOAD_OPS DEST ADDRESS
{
i_type_inst ($1.i == Y_LD_POP ? Y_LW_OP : $1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
if ($1.i == Y_LD_POP)
i_type_inst_free (Y_LW_OP,
$2.i + 1,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
4));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| LOADC_OPS COP_REG ADDRESS
{
i_type_inst ($1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| LOADFP_OPS F_SRC1 ADDRESS
{
i_type_inst ($1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| LOADI_OPS DEST UIMM16
{
i_type_inst_free ($1.i, $2.i, 0, (imm_expr *)$3.p);
}
| Y_LA_POP DEST ADDRESS
{
if (addr_expr_reg ((addr_expr *)$3.p))
i_type_inst (Y_ADDI_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
else
i_type_inst (Y_ORI_OP, $2.i, 0,
addr_expr_imm ((addr_expr *)$3.p));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| Y_LI_POP DEST IMM32
{
i_type_inst_free (Y_ORI_OP, $2.i, 0, (imm_expr *)$3.p);
}
| Y_LI_D_POP F_DEST Y_FP
{
int *x = (int *) $3.p;
i_type_inst (Y_ORI_OP, 1, 0, const_imm_expr (*x));
r_co_type_inst (Y_MTC1_OP, 0, $2.i, 1);
i_type_inst (Y_ORI_OP, 1, 0, const_imm_expr (*(x+1)));
r_co_type_inst (Y_MTC1_OP, 0, $2.i + 1, 1);
}
| Y_LI_S_POP F_DEST Y_FP
{
float x = (float) *((double *) $3.p);
int *y = (int *) &x;
i_type_inst (Y_ORI_OP, 1, 0, const_imm_expr (*y));
r_co_type_inst (Y_MTC1_OP, 0, $2.i, 1);
}
| Y_ULW_POP DEST ADDRESS
{
#ifdef BIGENDIAN
i_type_inst (Y_LWL_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
i_type_inst_free (Y_LWR_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
3));
#else
i_type_inst_free (Y_LWL_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
3));
i_type_inst (Y_LWR_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
#endif
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| ULOADH_POPS DEST ADDRESS
{
#ifdef BIGENDIAN
i_type_inst (($1.i == Y_ULH_POP ? Y_LB_OP : Y_LBU_OP),
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
i_type_inst_free (Y_LBU_OP, 1,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
1));
#else
i_type_inst_free (($1.i == Y_ULH_POP ? Y_LB_OP : Y_LBU_OP),
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
1));
i_type_inst (Y_LBU_OP, 1,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
#endif
r_sh_type_inst (Y_SLL_OP, $2.i, $2.i, 8);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| LOADFP_INDEX_OPS F_DEST ADDRESS
{
mips32_r2_inst ();
}
| STORE_OPS SRC1 ADDRESS
{
i_type_inst ($1.i == Y_SD_POP ? Y_SW_OP : $1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
if ($1.i == Y_SD_POP)
i_type_inst_free (Y_SW_OP, $2.i + 1,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
4));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| STOREC_OPS COP_REG ADDRESS
{
i_type_inst ($1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| Y_USW_POP SRC1 ADDRESS
{
#ifdef BIGENDIAN
i_type_inst (Y_SWL_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
i_type_inst_free (Y_SWR_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
3));
#else
i_type_inst_free (Y_SWL_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
3));
i_type_inst (Y_SWR_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
#endif
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| Y_USH_POP SRC1 ADDRESS
{
i_type_inst (Y_SB_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
/* ROL SRC, SRC, 8 */
r_sh_type_inst (Y_SLL_OP, 1, $2.i, 24);
r_sh_type_inst (Y_SRL_OP, $2.i, $2.i, 8);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
i_type_inst_free (Y_SB_OP, $2.i,
addr_expr_reg ((addr_expr *)$3.p),
incr_expr_offset (addr_expr_imm ((addr_expr *)$3.p),
1));
/* ROR SRC, SRC, 8 */
r_sh_type_inst (Y_SRL_OP, 1, $2.i, 24);
r_sh_type_inst (Y_SLL_OP, $2.i, $2.i, 8);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| STOREFP_OPS F_SRC1 ADDRESS
{
i_type_inst ($1.i,
$2.i,
addr_expr_reg ((addr_expr *)$3.p),
addr_expr_imm ((addr_expr *)$3.p));
free (((addr_expr *)$3.p)->imm);
free ((addr_expr *)$3.p);
}
| STOREFP_INDEX_OPS F_DEST ADDRESS
{
mips32_r2_inst ();
}
| SYS_OPS
{
r_type_inst ($1.i, 0, 0, 0);
}
| PREFETCH_OPS ADDRESS
{
mips32_r2_inst ();
}
| CACHE_OPS Y_INT ADDRESS
{
i_type_inst_free ($1.i, $2.i, 0, (imm_expr *)$3.p);
}
| TLB_OPS
{
r_type_inst ($1.i, 0, 0, 0);
}
| Y_SYNC_OP
{
r_type_inst ($1.i, 0, 0, 0);
}
| Y_SYNC_OP Y_INT
{
r_type_inst ($1.i, $2.i, 0, 0);
}
| Y_BREAK_OP Y_INT
{
if ($2.i == 1)
yyerror ("Breakpoint 1 is reserved for debugger");
r_type_inst ($1.i, $2.i, 0, 0);
}
| Y_NOP_POP
{
nop_inst ();
}
| Y_SSNOP_OP
{
r_sh_type_inst (Y_SLL_OP, 0, 0, 1); /* SLL r0 r0 1 */
}
| Y_ABS_POP DEST SRC1
{
if ($2.i != $3.i)
r_type_inst (Y_ADDU_OP, $2.i, 0, $3.i);
i_type_inst_free (Y_BGEZ_OP, 0, $3.i, branch_offset (2));
r_type_inst (Y_SUB_OP, $2.i, 0, $3.i);
}
| Y_NEG_POP DEST SRC1
{
r_type_inst (Y_SUB_OP, $2.i, 0, $3.i);
}
| Y_NEGU_POP DEST SRC1
{
r_type_inst (Y_SUBU_OP, $2.i, 0, $3.i);
}
| Y_NOT_POP DEST SRC1
{
r_type_inst (Y_NOR_OP, $2.i, $3.i, 0);
}
| Y_MOVE_POP DEST SRC1
{
r_type_inst (Y_ADDU_OP, $2.i, 0, $3.i);
}
| NULLARY_OPS
{
r_type_inst ($1.i, 0, 0, 0);
}
| NULLARY_OPS_REV2
{
mips32_r2_inst ();
}
| COUNT_LEADING_OPS DEST SRC1
{
/* RT must be equal to RD */
r_type_inst ($1.i, $2.i, $3.i, $2.i);
}
| UNARY_OPS_REV2 DEST
{
mips32_r2_inst ();
}
| BINARYI_OPS DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| BINARYI_OPS DEST SRC1 IMM32
{
i_type_inst_free (op_to_imm_op ($1.i), $2.i, $3.i,
(imm_expr *)$4.p);
}
| BINARYI_OPS DEST IMM32
{
i_type_inst_free (op_to_imm_op ($1.i), $2.i, $2.i,
(imm_expr *)$3.p);
}
| BINARYIR_OPS DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $4.i, $3.i);
}
| BINARYIR_OPS DEST SRC1 Y_INT
{
r_sh_type_inst (op_to_imm_op ($1.i), $2.i, $3.i, $4.i);
}
| BINARYIR_OPS DEST Y_INT
{
r_sh_type_inst (op_to_imm_op ($1.i), $2.i, $2.i, $3.i);
}
| BINARY_ARITHI_OPS DEST SRC1 IMM16
{
i_type_inst_free ($1.i, $2.i, $3.i, (imm_expr *)$4.p);
}
| BINARY_ARITHI_OPS DEST IMM16
{
i_type_inst_free ($1.i, $2.i, $2.i, (imm_expr *)$3.p);
}
| BINARY_LOGICALI_OPS DEST SRC1 UIMM16
{
i_type_inst_free ($1.i, $2.i, $3.i, (imm_expr *)$4.p);
}
| BINARY_LOGICALI_OPS DEST UIMM16
{
i_type_inst_free ($1.i, $2.i, $2.i, (imm_expr *)$3.p);
}
| SHIFT_OPS DEST SRC1 Y_INT
{
if (($4.i < 0) || (31 < $4.i))
yywarn ("Shift distance can only be in the range 0..31");
r_sh_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| SHIFT_OPS DEST SRC1 SRC2
{
r_type_inst (imm_op_to_op ($1.i), $2.i, $4.i, $3.i);
}
| SHIFT_OPS_REV2 DEST SRC1 Y_INT
{
mips32_r2_inst ();
}
| SHIFTV_OPS_REV2 DEST SRC1 SRC2
{
mips32_r2_inst ();
}
| BINARY_OPS DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| BINARY_OPS DEST SRC1 IMM32
{
if (bare_machine && !accept_pseudo_insts)
yyerror ("Immediate form not allowed in bare machine");
else
{
if (!zero_imm ((imm_expr *)$4.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
r_type_inst ($1.i,
$2.i,
$3.i,
(zero_imm ((imm_expr *)$4.p) ? 0 : 1));
}
free ((imm_expr *)$4.p);
}
| BINARY_OPS DEST IMM32
{
check_uimm_range ((imm_expr *)$3.p, UIMM_MIN, UIMM_MAX);
if (bare_machine && !accept_pseudo_insts)
yyerror ("Immediate form not allowed in bare machine");
else
{
if (!zero_imm ((imm_expr *)$3.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$3.p);
r_type_inst ($1.i,
$2.i,
$2.i,
(zero_imm ((imm_expr *)$3.p) ? 0 : 1));
}
free ((imm_expr *)$3.p);
}
| BINARY_OPS_REV2 DEST SRC1
{
mips32_r2_inst ();
}
| SUB_OPS DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| SUB_OPS DEST SRC1 IMM32
{
int val = eval_imm_expr ((imm_expr *)$4.p);
if (bare_machine && !accept_pseudo_insts)
yyerror ("Immediate form not allowed in bare machine");
else
i_type_inst ($1.i == Y_SUB_OP ? Y_ADDI_OP
: $1.i == Y_SUBU_OP ? Y_ADDIU_OP
: (fatal_error ("Bad SUB_OP\n"), 0),
$2.i,
$3.i,
make_imm_expr (-val, NULL, 0));
free ((imm_expr *)$4.p);
}
| SUB_OPS DEST IMM32
{
int val = eval_imm_expr ((imm_expr *)$3.p);
if (bare_machine && !accept_pseudo_insts)
yyerror ("Immediate form not allowed in bare machine");
else
i_type_inst ($1.i == Y_SUB_OP ? Y_ADDI_OP
: $1.i == Y_SUBU_OP ? Y_ADDIU_OP
: (fatal_error ("Bad SUB_OP\n"), 0),
$2.i,
$2.i,
make_imm_expr (-val, NULL, 0));
free ((imm_expr *)$3.p);
}
| DIV_POPS DEST SRC1
{
/* The hardware divide operation (ignore 1st arg) */
if ($1.i != Y_DIV_OP && $1.i != Y_DIVU_OP)
yyerror ("REM requires 3 arguments");
else
r_type_inst ($1.i, 0, $2.i, $3.i);
}
| DIV_POPS DEST SRC1 SRC2
{
/* Pseudo divide operations */
div_inst ($1.i, $2.i, $3.i, $4.i, 0);
}
| DIV_POPS DEST SRC1 IMM32
{
if (zero_imm ((imm_expr *)$4.p))
yyerror ("Divide by zero");
else
{
/* Use $at */
i_type_inst_free (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
div_inst ($1.i, $2.i, $3.i, 1, 1);
}
}
| MUL_POPS DEST SRC1 SRC2
{
mult_inst ($1.i, $2.i, $3.i, $4.i);
}
| MUL_POPS DEST SRC1 IMM32
{
if (zero_imm ((imm_expr *)$4.p))
/* Optimize: n * 0 == 0 */
i_type_inst_free (Y_ORI_OP, $2.i, 0, (imm_expr *)$4.p);
else
{
/* Use $at */
i_type_inst_free (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
mult_inst ($1.i, $2.i, $3.i, 1);
}
}
| MULT_OPS SRC1 SRC2
{
r_type_inst ($1.i, 0, $2.i, $3.i);
}
| MULT_OPS3 DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| MULT_OPS3 DEST SRC1 IMM32
{
/* Special case, for backward compatibility with pseudo-op
MULT instruction */
i_type_inst_free (Y_ORI_OP, 1, 0, (imm_expr *)$4.p); /* Use $at */
r_type_inst ($1.i, $2.i, $3.i, 1);
}
| Y_ROR_POP DEST SRC1 SRC2
{
r_type_inst (Y_SUBU_OP, 1, 0, $4.i);
r_type_inst (Y_SLLV_OP, 1, 1, $3.i);
r_type_inst (Y_SRLV_OP, $2.i, $4.i, $3.i);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
}
| Y_ROL_POP DEST SRC1 SRC2
{
r_type_inst (Y_SUBU_OP, 1, 0, $4.i);
r_type_inst (Y_SRLV_OP, 1, 1, $3.i);
r_type_inst (Y_SLLV_OP, $2.i, $4.i, $3.i);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
}
| Y_ROR_POP DEST SRC1 IMM32
{
long dist = eval_imm_expr ((imm_expr *)$4.p);
check_imm_range ((imm_expr *)$4.p, 0, 31);
r_sh_type_inst (Y_SLL_OP, 1, $3.i, -dist);
r_sh_type_inst (Y_SRL_OP, $2.i, $3.i, dist);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
free ((imm_expr *)$4.p);
}
| Y_ROL_POP DEST SRC1 IMM32
{
long dist = eval_imm_expr ((imm_expr *)$4.p);
check_imm_range ((imm_expr *)$4.p, 0, 31);
r_sh_type_inst (Y_SRL_OP, 1, $3.i, -dist);
r_sh_type_inst (Y_SLL_OP, $2.i, $3.i, dist);
r_type_inst (Y_OR_OP, $2.i, $2.i, 1);
free ((imm_expr *)$4.p);
}
| BF_OPS_REV2 F_DEST F_SRC2 Y_INT Y_INT
{
mips32_r2_inst ();
}
| SET_LE_POPS DEST SRC1 SRC2
{
set_le_inst ($1.i, $2.i, $3.i, $4.i);
}
| SET_LE_POPS DEST SRC1 IMM32
{
if (!zero_imm ((imm_expr *)$4.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
set_le_inst ($1.i, $2.i, $3.i,
(zero_imm ((imm_expr *)$4.p) ? 0 : 1));
free ((imm_expr *)$4.p);
}
| SET_GT_POPS DEST SRC1 SRC2
{
set_gt_inst ($1.i, $2.i, $3.i, $4.i);
}
| SET_GT_POPS DEST SRC1 IMM32
{
if (!zero_imm ((imm_expr *)$4.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
set_gt_inst ($1.i, $2.i, $3.i,
(zero_imm ((imm_expr *)$4.p) ? 0 : 1));
free ((imm_expr *)$4.p);
}
| SET_GE_POPS DEST SRC1 SRC2
{
set_ge_inst ($1.i, $2.i, $3.i, $4.i);
}
| SET_GE_POPS DEST SRC1 IMM32
{
if (!zero_imm ((imm_expr *)$4.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
set_ge_inst ($1.i, $2.i, $3.i,
(zero_imm ((imm_expr *)$4.p) ? 0 : 1));
free ((imm_expr *)$4.p);
}
| SET_EQ_POPS DEST SRC1 SRC2
{
set_eq_inst ($1.i, $2.i, $3.i, $4.i);
}
| SET_EQ_POPS DEST SRC1 IMM32
{
if (!zero_imm ((imm_expr *)$4.p))
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$4.p);
set_eq_inst ($1.i, $2.i, $3.i,
(zero_imm ((imm_expr *)$4.p) ? 0 : 1));
free ((imm_expr *)$4.p);
}
| BR_COP_OPS LABEL
{
/* RS and RT fields contain information on test */
int nd = opcode_is_nullified_branch ($1.i);
int tf = opcode_is_true_branch ($1.i);
i_type_inst_free ($1.i,
cc_to_rt (0, nd, tf),
BIN_RS ($1.i),
(imm_expr *)$2.p);
}
| BR_COP_OPS CC_REG LABEL
{
/* RS and RT fields contain information on test */
int nd = opcode_is_nullified_branch ($1.i);
int tf = opcode_is_true_branch ($1.i);
i_type_inst_free ($1.i,
cc_to_rt ($2.i, nd, tf),
BIN_RS ($1.i),
(imm_expr *)$3.p);
}
| UNARY_BR_OPS SRC1 LABEL
{
i_type_inst_free ($1.i, 0, $2.i, (imm_expr *)$3.p);
}
| UNARY_BR_POPS SRC1 LABEL
{
i_type_inst_free ($1.i == Y_BEQZ_POP ? Y_BEQ_OP : Y_BNE_OP,
0, $2.i, (imm_expr *)$3.p);
}
| BINARY_BR_OPS SRC1 SRC2 LABEL
{
i_type_inst_free ($1.i, $3.i, $2.i, (imm_expr *)$4.p);
}
| BINARY_BR_OPS SRC1 BR_IMM32 LABEL
{
if (bare_machine && !accept_pseudo_insts)
yyerror ("Immediate form not allowed in bare machine");
else
{
if (zero_imm ((imm_expr *)$3.p))
i_type_inst ($1.i, $2.i,
(zero_imm ((imm_expr *)$3.p) ? 0 : 1),
(imm_expr *)$4.p);
else
{
/* Use $at */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$3.p);
i_type_inst ($1.i, $2.i,
(zero_imm ((imm_expr *)$3.p) ? 0 : 1),
(imm_expr *)$4.p);
}
}
free ((imm_expr *)$3.p);
free ((imm_expr *)$4.p);
}
| BR_GT_POPS SRC1 SRC2 LABEL
{
r_type_inst ($1.i == Y_BGT_POP ? Y_SLT_OP : Y_SLTU_OP,
1, $3.i, $2.i); /* Use $at */
i_type_inst_free (Y_BNE_OP, 0, 1, (imm_expr *)$4.p);
}
| BR_GT_POPS SRC1 BR_IMM32 LABEL
{
if ($1.i == Y_BGT_POP)
{
/* Use $at */
i_type_inst_free (Y_SLTI_OP, 1, $2.i,
incr_expr_offset ((imm_expr *)$3.p, 1));
i_type_inst (Y_BEQ_OP, 0, 1, (imm_expr *)$4.p);
}
else
{
/* Use $at */
/* Can't add 1 to immediate since 0xffffffff+1 = 0 < 1 */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$3.p);
i_type_inst_free (Y_BEQ_OP, $2.i, 1, branch_offset (3));
r_type_inst (Y_SLTU_OP, 1, $2.i, 1);
i_type_inst (Y_BEQ_OP, 0, 1, (imm_expr *)$4.p);
}
free ((imm_expr *)$3.p);
free ((imm_expr *)$4.p);
}
| BR_GE_POPS SRC1 SRC2 LABEL
{
r_type_inst ($1.i == Y_BGE_POP ? Y_SLT_OP : Y_SLTU_OP,
1, $2.i, $3.i); /* Use $at */
i_type_inst_free (Y_BEQ_OP, 0, 1, (imm_expr *)$4.p);
}
| BR_GE_POPS SRC1 BR_IMM32 LABEL
{
i_type_inst ($1.i == Y_BGE_POP ? Y_SLTI_OP : Y_SLTIU_OP,
1, $2.i, (imm_expr *)$3.p); /* Use $at */
i_type_inst_free (Y_BEQ_OP, 0, 1, (imm_expr *)$4.p);
free ((imm_expr *)$3.p);
}
| BR_LT_POPS SRC1 SRC2 LABEL
{
r_type_inst ($1.i == Y_BLT_POP ? Y_SLT_OP : Y_SLTU_OP,
1, $2.i, $3.i); /* Use $at */
i_type_inst_free (Y_BNE_OP, 0, 1, (imm_expr *)$4.p);
}
| BR_LT_POPS SRC1 BR_IMM32 LABEL
{
i_type_inst ($1.i == Y_BLT_POP ? Y_SLTI_OP : Y_SLTIU_OP,
1, $2.i, (imm_expr *)$3.p); /* Use $at */
i_type_inst_free (Y_BNE_OP, 0, 1, (imm_expr *)$4.p);
free ((imm_expr *)$3.p);
}
| BR_LE_POPS SRC1 SRC2 LABEL
{
r_type_inst ($1.i == Y_BLE_POP ? Y_SLT_OP : Y_SLTU_OP,
1, $3.i, $2.i); /* Use $at */
i_type_inst_free (Y_BEQ_OP, 0, 1, (imm_expr *)$4.p);
}
| BR_LE_POPS SRC1 BR_IMM32 LABEL
{
if ($1.i == Y_BLE_POP)
{
/* Use $at */
i_type_inst_free (Y_SLTI_OP, 1, $2.i,
incr_expr_offset ((imm_expr *)$3.p, 1));
i_type_inst (Y_BNE_OP, 0, 1, (imm_expr *)$4.p);
}
else
{
/* Use $at */
/* Can't add 1 to immediate since 0xffffffff+1 = 0 < 1 */
i_type_inst (Y_ORI_OP, 1, 0, (imm_expr *)$3.p);
i_type_inst (Y_BEQ_OP, $2.i, 1, (imm_expr *)$4.p);
r_type_inst (Y_SLTU_OP, 1, $2.i, 1);
i_type_inst (Y_BNE_OP, 0, 1, (imm_expr *)$4.p);
}
free ((imm_expr *)$3.p);
free ((imm_expr *)$4.p);
}
| J_OPS LABEL
{
if (($1.i == Y_J_OP) || ($1.i == Y_JR_OP))
j_type_inst (Y_J_OP, (imm_expr *)$2.p);
else if (($1.i == Y_JAL_OP) || ($1.i == Y_JALR_OP))
j_type_inst (Y_JAL_OP, (imm_expr *)$2.p);
free ((imm_expr *)$2.p);
}
| J_OPS SRC1
{
if (($1.i == Y_J_OP) || ($1.i == Y_JR_OP))
r_type_inst (Y_JR_OP, 0, $2.i, 0);
else if (($1.i == Y_JAL_OP) || ($1.i == Y_JALR_OP))
r_type_inst (Y_JALR_OP, 31, $2.i, 0);
}
| J_OPS DEST SRC1
{
if (($1.i == Y_J_OP) || ($1.i == Y_JR_OP))
r_type_inst (Y_JR_OP, 0, $3.i, 0);
else if (($1.i == Y_JAL_OP) || ($1.i == Y_JALR_OP))
r_type_inst (Y_JALR_OP, $2.i, $3.i, 0);
}
| B_OPS LABEL
{
i_type_inst_free (($1.i == Y_BAL_POP ? Y_BGEZAL_OP : Y_BGEZ_OP),
0, 0, (imm_expr *)$2.p);
}
| UNARY_TRAP_OPS SRC1 IMM16
{
i_type_inst_free ($1.i, 0, $2.i, (imm_expr *)$3.p);
}
| BINARY_TRAP_OPS SRC1 SRC2
{
r_type_inst ($1.i, 0, $2.i, $3.i);
}
| FP_MOVE_OPS F_DEST F_SRC1
{
r_co_type_inst ($1.i, $2.i, $3.i, 0);
}
| FP_MOVE_OPS_REV2 F_DEST F_SRC1
{
mips32_r2_inst ();
}
| MOVEC_OPS DEST SRC1 CC_REG
{
r_type_inst ($1.i, $2.i, $3.i, cc_to_rt ($4.i, 0, 0));
}
| FP_MOVEC_OPS F_DEST F_SRC1 REG
{
r_co_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| FP_MOVECC_OPS F_DEST F_SRC1 CC_REG
{
r_co_type_inst ($1.i, $2.i, $3.i, cc_to_rt ($4.i, 0, 0));
}
| FP_MOVECC_OPS_REV2 F_DEST F_SRC1 CC_REG
{
mips32_r2_inst ();
}
| FP_MOVEC_OPS_REV2 F_DEST F_SRC1 REG
{
mips32_r2_inst ();
}
| MOVE_FROM_HILO_OPS REG
{
r_type_inst ($1.i, $2.i, 0, 0);
}
| MOVE_TO_HILO_OPS REG
{
r_type_inst ($1.i, 0, $2.i, 0);
}
| MOVEC_OPS DEST SRC1 SRC2
{
r_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| MOVE_COP_OPS REG COP_REG
{
if ($1.i == Y_MFC1_D_POP)
{
r_co_type_inst (Y_MFC1_OP, 0, $3.i, $2.i);
r_co_type_inst (Y_MFC1_OP, 0, $3.i + 1, $2.i + 1);
}
else if ($1.i == Y_MTC1_D_POP)
{
r_co_type_inst (Y_MTC1_OP, 0, $3.i, $2.i);
r_co_type_inst (Y_MTC1_OP, 0, $3.i + 1, $2.i + 1);
}
else
r_co_type_inst ($1.i, 0, $3.i, $2.i);
}
| MOVE_COP_OPS_REV2 REG COP_REG
{
mips32_r2_inst ();
}
| CTL_COP_OPS REG COP_REG
{
r_co_type_inst ($1.i, 0, $3.i, $2.i);
}
| FP_UNARY_OPS F_DEST F_SRC2
{
r_co_type_inst ($1.i, $2.i, $3.i, 0);
}
| FP_UNARY_OPS_REV2 F_DEST F_SRC2
{
mips32_r2_inst ();
}
| FP_BINARY_OPS F_DEST F_SRC1 F_SRC2
{
r_co_type_inst ($1.i, $2.i, $3.i, $4.i);
}
| FP_BINARY_OPS_REV2 F_DEST F_SRC1 F_SRC2
{
mips32_r2_inst ();
}
| FP_TERNARY_OPS_REV2 F_DEST F_SRC1 F_SRC2 FP_REGISTER
{
mips32_r2_inst ();
}
| FP_CMP_OPS F_SRC1 F_SRC2
{
r_cond_type_inst ($1.i, $2.i, $3.i, 0);
}
| FP_CMP_OPS CC_REG F_SRC1 F_SRC2
{
r_cond_type_inst ($1.i, $3.i, $4.i, $2.i);
}
| FP_CMP_OPS_REV2 F_SRC1 F_SRC2
{
mips32_r2_inst ();
}
| Y_COP2_OP IMM32
{
i_type_inst_free ($1.i, 0, 0, (imm_expr *)$2.p);
}
;
LOAD_OPS: Y_LB_OP
| Y_LBU_OP
| Y_LH_OP
| Y_LHU_OP
| Y_LL_OP
| Y_LW_OP
| Y_LWL_OP
| Y_LWR_OP
| Y_PFW_OP
| Y_LD_POP
;
LOADI_OPS: Y_LUI_OP
;
ULOADH_POPS: Y_ULH_POP
| Y_ULHU_POP
;
LOADC_OPS: Y_LDC2_OP
| Y_LWC2_OP
;
LOADFP_OPS: Y_LDC1_OP
| Y_LWC1_OP
| Y_L_D_POP { $$.i = Y_LDC1_OP; }
| Y_L_S_POP { $$.i = Y_LWC1_OP; }
;
LOADFP_INDEX_OPS: Y_LDXC1_OP
| Y_LUXC1_OP
| Y_LWXC1_OP
;
STORE_OPS: Y_SB_OP
| Y_SC_OP
| Y_SH_OP
| Y_SW_OP
| Y_SWL_OP
| Y_SWR_OP
| Y_SD_POP
;
STOREC_OPS: Y_SWC2_OP
| Y_SDC2_OP
| Y_S_D_POP { $$.i = Y_SDC1_OP; }
| Y_S_S_POP { $$.i = Y_SWC1_OP; }
;
STOREFP_OPS: Y_SWC1_OP
| Y_SDC1_OP
;
STOREFP_INDEX_OPS: Y_SDXC1_OP
| Y_SUXC1_OP
| Y_SWXC1_OP
;
SYS_OPS: Y_RFE_OP
{
#ifdef MIPS1
yywarn ("RFE should only be used when SPIM is compiled as a MIPS-I processor");
#endif
}
| Y_SYSCALL_OP
;
PREFETCH_OPS: Y_PREFX_OP
| Y_SYNCI_OP
;
CACHE_OPS: Y_CACHE_OP
| Y_PREF_OP
;
TLB_OPS: Y_TLBP_OP
| Y_TLBR_OP
| Y_TLBWI_OP
| Y_TLBWR_OP
;
NULLARY_OPS: Y_ERET_OP
{
#ifdef MIPS1
yywarn ("ERET should only be used when SPIM is compiled as a MIPS32 processor");
#endif
}
;
NULLARY_OPS_REV2: Y_DERET_OP
| Y_EHB_OP
| Y_SDBBP_OP
;
COUNT_LEADING_OPS: Y_CLO_OP
| Y_CLZ_OP
;
UNARY_OPS_REV2: Y_DI_OP
| Y_EI_OP
;
/* These binary operations have immediate analogues. */
BINARYI_OPS: Y_ADD_OP
| Y_ADDU_OP
| Y_AND_OP
| Y_XOR_OP
| Y_OR_OP
| Y_SLT_OP
| Y_SLTU_OP
;
BINARYIR_OPS: Y_SLLV_OP
| Y_SRAV_OP
| Y_SRLV_OP
;
BINARY_ARITHI_OPS: Y_ADDI_OP
| Y_ADDIU_OP
| Y_SLTI_OP
| Y_SLTIU_OP
;
BINARY_LOGICALI_OPS: Y_ANDI_OP
| Y_ORI_OP
| Y_XORI_OP
;
SHIFT_OPS: Y_SLL_OP
| Y_SRA_OP
| Y_SRL_OP
;
SHIFT_OPS_REV2: Y_ROTR_OP
;
SHIFTV_OPS_REV2: Y_ROTRV_OP
;
/* These binary operations do not have immediate analogues. */
BINARY_OPS: Y_NOR_OP
;
BINARY_OPS_REV2: Y_RDHWR_OP
| Y_RDPGPR_OP
| Y_SEB_OP
| Y_SEH_OP
| Y_WRPGPR_OP
| Y_WSBH_OP
;
SUB_OPS: Y_SUB_OP
| Y_SUBU_OP
;
DIV_POPS: Y_DIV_OP
| Y_DIVU_OP
| Y_REM_POP
| Y_REMU_POP
;
MUL_POPS: Y_MULO_POP
| Y_MULOU_POP
;
SET_LE_POPS: Y_SLE_POP
| Y_SLEU_POP
;
SET_GT_POPS: Y_SGT_POP
| Y_SGTU_POP
;
SET_GE_POPS: Y_SGE_POP
| Y_SGEU_POP
;
SET_EQ_POPS: Y_SEQ_POP
| Y_SNE_POP
;
MULT_OPS: Y_MULT_OP
| Y_MULTU_OP
| Y_MADD_OP
| Y_MADDU_OP
| Y_MSUB_OP
| Y_MSUBU_OP
;
MULT_OPS3: Y_MUL_OP
;
BF_OPS_REV2: Y_EXT_OP
| Y_INS_OP
;
BR_COP_OPS: Y_BC1F_OP
| Y_BC1FL_OP
| Y_BC1T_OP
| Y_BC1TL_OP
| Y_BC2F_OP
| Y_BC2FL_OP
| Y_BC2T_OP
| Y_BC2TL_OP
;
UNARY_BR_OPS: Y_BGEZ_OP
| Y_BGEZL_OP
| Y_BGEZAL_OP
| Y_BGEZALL_OP
| Y_BGTZ_OP
| Y_BGTZL_OP
| Y_BLEZ_OP
| Y_BLEZL_OP
| Y_BLTZ_OP
| Y_BLTZL_OP
| Y_BLTZAL_OP
| Y_BLTZALL_OP
;
UNARY_BR_POPS: Y_BEQZ_POP
| Y_BNEZ_POP
;
BINARY_BR_OPS: Y_BEQ_OP
| Y_BEQL_OP
| Y_BNE_OP
| Y_BNEL_OP
;
BR_GT_POPS: Y_BGT_POP
| Y_BGTU_POP
BR_GE_POPS: Y_BGE_POP
| Y_BGEU_POP
BR_LT_POPS: Y_BLT_POP
| Y_BLTU_POP
BR_LE_POPS: Y_BLE_POP
| Y_BLEU_POP
;
J_OPS: Y_J_OP
| Y_JR_OP
| Y_JR_HB_OP { yywarn ("Warning:IPS32 Rev 2 '.HB' extension is not implemented and is ignored"); }
| Y_JAL_OP
| Y_JALR_OP
| Y_JALR_HB_OP { yywarn ("Warning:IPS32 Rev 2 '.HB' extension is not implemented and is ignored"); }
;
B_OPS: Y_B_POP
| Y_BAL_POP
;
UNARY_TRAP_OPS: Y_TEQI_OP
| Y_TGEI_OP
| Y_TGEIU_OP
| Y_TLTI_OP
| Y_TLTIU_OP
| Y_TNEI_OP
;
BINARY_TRAP_OPS: Y_TEQ_OP
| Y_TGE_OP
| Y_TGEU_OP
| Y_TLT_OP
| Y_TLTU_OP
| Y_TNE_OP
;
MOVE_FROM_HILO_OPS: Y_MFHI_OP
| Y_MFLO_OP
;
MOVE_TO_HILO_OPS: Y_MTHI_OP
| Y_MTLO_OP
;
MOVEC_OPS: Y_MOVN_OP
| Y_MOVZ_OP
;
MOVE_COP_OPS: Y_MFC0_OP
| Y_MFC1_OP
| Y_MFC1_D_POP
| Y_MFC2_OP
| Y_MTC0_OP
| Y_MTC1_OP
| Y_MTC1_D_POP
| Y_MTC2_OP
;
MOVE_COP_OPS_REV2: Y_MFHC1_OP
| Y_MFHC2_OP
| Y_MTHC1_OP
| Y_MTHC2_OP
;
CTL_COP_OPS: Y_CFC0_OP
| Y_CFC1_OP
| Y_CFC2_OP
| Y_CTC0_OP
| Y_CTC1_OP
| Y_CTC2_OP
;
/* Floating point operations */
FP_MOVE_OPS: Y_MOV_S_OP
| Y_MOV_D_OP
;
FP_MOVE_OPS_REV2: Y_MOV_PS_OP
;
MOVEC_OPS: Y_MOVF_OP
| Y_MOVT_OP
;
FP_MOVEC_OPS: Y_MOVN_D_OP
| Y_MOVN_S_OP
| Y_MOVZ_D_OP
| Y_MOVZ_S_OP
;
FP_MOVEC_OPS_REV2: Y_MOVN_PS_OP
| Y_MOVZ_PS_OP
;
FP_MOVECC_OPS: Y_MOVF_D_OP
| Y_MOVF_S_OP
| Y_MOVT_D_OP
| Y_MOVT_S_OP
;
FP_MOVECC_OPS_REV2: Y_MOVF_PS_OP
| Y_MOVT_PS_OP
;
FP_UNARY_OPS: Y_ABS_S_OP
| Y_ABS_D_OP
| Y_CEIL_W_D_OP
| Y_CEIL_W_S_OP
| Y_CVT_D_S_OP
| Y_CVT_D_W_OP
| Y_CVT_S_D_OP
| Y_CVT_S_W_OP
| Y_CVT_W_D_OP
| Y_CVT_W_S_OP
| Y_FLOOR_W_D_OP
| Y_FLOOR_W_S_OP
| Y_NEG_S_OP
| Y_NEG_D_OP
| Y_ROUND_W_D_OP
| Y_ROUND_W_S_OP
| Y_SQRT_D_OP
| Y_SQRT_S_OP
| Y_TRUNC_W_D_OP
| Y_TRUNC_W_S_OP
;
FP_UNARY_OPS_REV2: Y_ABS_PS_OP
| Y_CEIL_L_D_OP
| Y_CEIL_L_S_OP
| Y_CVT_D_L_OP
| Y_CVT_L_D_OP
| Y_CVT_L_S_OP
| Y_CVT_PS_S_OP
| Y_CVT_S_L_OP
| Y_CVT_S_PL_OP
| Y_CVT_S_PU_OP
| Y_FLOOR_L_D_OP
| Y_FLOOR_L_S_OP
| Y_NEG_PS_OP
| Y_RECIP_D_OP
| Y_RECIP_S_OP
| Y_ROUND_L_D_OP
| Y_ROUND_L_S_OP
| Y_RSQRT_D_OP
| Y_RSQRT_S_OP
| Y_TRUNC_L_D_OP
| Y_TRUNC_L_S_OP
;
FP_BINARY_OPS: Y_ADD_S_OP
| Y_ADD_D_OP
| Y_DIV_S_OP
| Y_DIV_D_OP
| Y_MUL_S_OP
| Y_MUL_D_OP
| Y_SUB_S_OP
| Y_SUB_D_OP
;
FP_BINARY_OPS_REV2: Y_ADD_PS_OP
| Y_MUL_PS_OP
| Y_PLL_PS_OP
| Y_PLU_PS_OP
| Y_PUL_PS_OP
| Y_PUU_PS_OP
;
FP_TERNARY_OPS_REV2: Y_ALNV_PS_OP
| Y_MADD_D_OP
| Y_MADD_PS_OP
| Y_MADD_S_OP
| Y_MSUB_D_OP
| Y_MSUB_PS_OP
| Y_MSUB_S_OP
| Y_NMADD_D_OP
| Y_NMADD_PS_OP
| Y_NMADD_S_OP
| Y_NMSUB_D_OP
| Y_NMSUB_PS_OP
| Y_NMSUB_S_OP
;
FP_CMP_OPS: Y_C_F_S_OP
| Y_C_UN_S_OP
| Y_C_EQ_S_OP
| Y_C_UEQ_S_OP
| Y_C_OLT_S_OP
| Y_C_OLE_S_OP
| Y_C_ULT_S_OP
| Y_C_ULE_S_OP
| Y_C_SF_S_OP
| Y_C_NGLE_S_OP
| Y_C_SEQ_S_OP
| Y_C_NGL_S_OP
| Y_C_LT_S_OP
| Y_C_NGE_S_OP
| Y_C_LE_S_OP
| Y_C_NGT_S_OP
| Y_C_F_D_OP
| Y_C_UN_D_OP
| Y_C_EQ_D_OP
| Y_C_UEQ_D_OP
| Y_C_OLT_D_OP
| Y_C_OLE_D_OP
| Y_C_ULT_D_OP
| Y_C_ULE_D_OP
| Y_C_SF_D_OP
| Y_C_NGLE_D_OP
| Y_C_SEQ_D_OP
| Y_C_NGL_D_OP
| Y_C_LT_D_OP
| Y_C_NGE_D_OP
| Y_C_LE_D_OP
| Y_C_NGT_D_OP
;
FP_CMP_OPS_REV2: Y_C_EQ_PS_OP
| Y_C_F_PS_OP
| Y_C_LT_PS_OP
| Y_C_LE_PS_OP
| Y_C_NGE_PS_OP
| Y_C_NGL_PS_OP
| Y_C_NGLE_PS_OP
| Y_C_NGT_PS_OP
| Y_C_OLE_PS_OP
| Y_C_OLT_PS_OP
| Y_C_SEQ_PS_OP
| Y_C_SF_PS_OP
| Y_C_UEQ_PS_OP
| Y_C_ULE_PS_OP
| Y_C_ULT_PS_OP
| Y_C_UN_PS_OP
;
ASM_DIRECTIVE: Y_ALIAS_DIR Y_REG Y_REG
| Y_ALIGN_DIR EXPR
{
align_data ($2.i);
}
| Y_ASCII_DIR {null_term = 0;} STR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_ASCIIZ_DIR {null_term = 1;} STR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_ASM0_DIR
| Y_BGNB_DIR Y_INT
| Y_BYTE_DIR
{store_op = store_byte;}
EXPR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_COMM_DIR ID EXPR
{
align_data (2);
if (lookup_label ((char*)$2.p)->addr == 0)
{
(void)record_label ((char*)$2.p, current_data_pc (), 1);
free ((char*)$2.p);
}
increment_data_pc ($3.i);
}
| Y_DATA_DIR
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
}
| Y_DATA_DIR Y_INT
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
set_data_pc ($2.i);
}
| Y_K_DATA_DIR
{
user_kernel_data_segment (1);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
}
| Y_K_DATA_DIR Y_INT
{
user_kernel_data_segment (1);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
set_data_pc ($2.i);
}
| Y_DOUBLE_DIR
{
store_op = store_double;
if (data_dir) set_data_alignment (3);
}
FP_EXPR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_END_DIR OPTIONAL_ID
| Y_ENDB_DIR Y_INT
| Y_ENDR_DIR
| Y_ENT_DIR ID
| Y_ENT_DIR ID Y_INT
| Y_EXTERN_DIR ID EXPR
{
extern_directive ((char*)$2.p, $3.i);
}
| Y_ERR_DIR
{
fatal_error ("File contains an .err directive\n");
}
| Y_FILE_DIR Y_INT Y_STR
| Y_FLOAT_DIR
{
store_op = store_float;
if (data_dir) set_data_alignment (2);
}
FP_EXPR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_FMASK_DIR Y_INT Y_INT
| Y_FRAME_DIR REGISTER Y_INT REGISTER
| Y_GLOBAL_DIR ID
{
(void)make_label_global ((char*)$2.p);
free ((char*)$2.p);
}
| Y_HALF_DIR
{
store_op = store_half;
if (data_dir) set_data_alignment (1);
}
EXPR_LST
{
if (text_dir)
yyerror ("Can't put data in text segment");
}
| Y_LABEL_DIR ID
{
(void)record_label ((char*)$2.p,
text_dir
? current_text_pc ()
: current_data_pc (),
1);
free ((char*)$2.p);
}
| Y_LCOMM_DIR ID EXPR
{
lcomm_directive ((char*)$2.p, $3.i);
}
/* Produced by cc 2.10 */
| Y_LIVEREG_DIR Y_INT Y_INT
| Y_LOC_DIR Y_INT Y_INT
| Y_MASK_DIR Y_INT Y_INT
| Y_NOALIAS_DIR Y_REG Y_REG
| Y_OPTIONS_DIR ID
| Y_REPEAT_DIR EXPR
{
yyerror ("Warning: repeat directive ignored");
}
| Y_RDATA_DIR
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
}
| Y_RDATA_DIR Y_INT
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
set_data_pc ($2.i);
}
| Y_SDATA_DIR
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
}
| Y_SDATA_DIR Y_INT
{
user_kernel_data_segment (0);
data_dir = 1; text_dir = 0;
enable_data_alignment ();
set_data_pc ($2.i);
}
| Y_SET_DIR ID
{
if (streq ((char*)$2.p, "noat"))
noat_flag = 1;
else if (streq ((char*)$2.p, "at"))
noat_flag = 0;
}
| Y_SPACE_DIR EXPR
{
if (data_dir)
increment_data_pc ($2.i);
else if (text_dir)
increment_text_pc ($2.i);
}
| Y_STRUCT_DIR EXPR
{
yyerror ("Warning: struct directive ignored");
}
| Y_TEXT_DIR
{
user_kernel_text_segment (0);
data_dir = 0; text_dir = 1;
enable_data_alignment ();
}
| Y_TEXT_DIR Y_INT
{
user_kernel_text_segment (0);
data_dir = 0; text_dir = 1;
enable_data_alignment ();
set_text_pc ($2.i);
}
| Y_K_TEXT_DIR
{
user_kernel_text_segment (1);
data_dir = 0; text_dir = 1;
enable_data_alignment ();
}
| Y_K_TEXT_DIR Y_INT
{
user_kernel_text_segment (1);
data_dir = 0; text_dir = 1;
enable_data_alignment ();
set_text_pc ($2.i);
}
| Y_VERSTAMP_DIR Y_INT Y_INT
| Y_VREG_DIR REGISTER Y_INT Y_INT
| Y_WORD_DIR
{
store_op = store_word_data;
if (data_dir) set_data_alignment (2);
}
EXPR_LST
;
ADDRESS: {only_id = 1;} ADDR {only_id = 0; $$ = $2;}
ADDR: '(' REGISTER ')'
{
$$.p = make_addr_expr (0, NULL, $2.i);
}
| ABS_ADDR
{
$$.p = make_addr_expr ($1.i, NULL, 0);
}
| ABS_ADDR '(' REGISTER ')'
{
$$.p = make_addr_expr ($1.i, NULL, $3.i);
}
| Y_ID
{
$$.p = make_addr_expr (0, (char*)$1.p, 0);
free ((char*)$1.p);
}
| Y_ID '(' REGISTER ')'
{
$$.p = make_addr_expr (0, (char*)$1.p, $3.i);
free ((char*)$1.p);
}
| Y_ID '+' ABS_ADDR
{
$$.p = make_addr_expr ($3.i, (char*)$1.p, 0);
free ((char*)$1.p);
}
| ABS_ADDR '+' ID
{
$$.p = make_addr_expr ($1.i, (char*)$3.p, 0);
}
| Y_ID '-' ABS_ADDR
{
$$.p = make_addr_expr (- $3.i, (char*)$1.p, 0);
free ((char*)$1.p);
}
| Y_ID '+' ABS_ADDR '(' REGISTER ')'
{
$$.p = make_addr_expr ($3.i, (char*)$1.p, $5.i);
free ((char*)$1.p);
}
| Y_ID '-' ABS_ADDR '(' REGISTER ')'
{
$$.p = make_addr_expr (- $3.i, (char*)$1.p, $5.i);
free ((char*)$1.p);
}
;
BR_IMM32: {only_id = 1;} IMM32 {only_id = 0; $$ = $2;}
IMM16: IMM32
{
check_imm_range ($1.p, IMM_MIN, IMM_MAX);
$$ = $1;
}
UIMM16: IMM32
{
check_uimm_range ($1.p, UIMM_MIN, UIMM_MAX);
$$ = $1;
}
IMM32: ABS_ADDR
{
$$.p = make_imm_expr ($1.i, NULL, 0);
}
| '(' ABS_ADDR ')' '>' '>' Y_INT
{
$$.p = make_imm_expr ($2.i >> $6.i, NULL, 0);
}
| ID
{
$$.p = make_imm_expr (0, (char*)$1.p, 0);
}
| Y_ID '+' ABS_ADDR
{
$$.p = make_imm_expr ($3.i, (char*)$1.p, 0);
free ((char*)$1.p);
}
| Y_ID '-' ABS_ADDR
{
$$.p = make_imm_expr (- $3.i, (char*)$1.p, 0);
free ((char*)$1.p);
}
;
ABS_ADDR: Y_INT
| Y_INT '+' Y_INT
{$$.i = $1.i + $3.i;}
| Y_INT Y_INT
{
/* This is actually: Y_INT '-' Y_INT, since the binary
subtract operator gets scanned as a unary negation
operator. */
if ($2.i >= 0) yyerror ("Syntax error");
$$.i = $1.i - -$2.i;
}
;
SRC1: REGISTER ;
SRC2: REGISTER ;
DEST: REGISTER ;
REG: REGISTER ;
REGISTER: Y_REG
{
if ($1.i < 0 || $1.i > 31)
yyerror ("Register number out of range");
if ($1.i == 1 && !bare_machine && !noat_flag)
yyerror ("Register 1 is reserved for assembler");
$$ = $1;
}
F_DEST: FP_REGISTER ;
F_SRC1: FP_REGISTER ;
F_SRC2: FP_REGISTER ;
FP_REGISTER: Y_FP_REG
{
if ($1.i < 0 || $1.i > 31)
yyerror ("FP register number out of range");
$$ = $1;
}
CC_REG: Y_INT
{
if ($1.i < 0 || $1.i > 7)
yyerror ("CC register number out of range");
$$ = $1;
}
COP_REG: Y_REG
| Y_FP_REG
;
LABEL: ID
{
$$.p = make_imm_expr (-(int)current_text_pc (), (char*)$1.p, 1);
}
STR_LST: STR_LST STR
| STR
;
STR: Y_STR
{
store_string ((char*)$1.p, strlen((char*)$1.p), null_term);
free ((char*)$1.p);
}
| Y_STR ':' Y_INT
{
int i;
for (i = 0; i < $3.i; i ++)
store_string ((char*)$1.p, strlen((char*)$1.p), null_term);
free ((char*)$1.p);
}
;
EXPRESSION: {only_id = 1;} EXPR {only_id = 0; $$ = $2;}
EXPR: Y_INT
| ID
{
label *l = lookup_label ((char*)$1.p);
if (l->addr == 0)
{
record_data_uses_symbol (current_data_pc (), l);
$$.p = NULL;
}
else
$$.i = l->addr;
}
EXPR_LST: EXPR_LST EXPRESSION
{
store_op ($2.p);
}
| EXPRESSION
{
store_op ($1.p);
}
| EXPRESSION ':' Y_INT
{
int i;
for (i = 0; i < $3.i; i ++)
store_op ($1.p);
}
;
FP_EXPR_LST: FP_EXPR_LST Y_FP
{
store_op ($2.p);
}
| Y_FP
{
store_op ($1.p);
}
;
OPTIONAL_ID: {only_id = 1;} OPT_ID {only_id = 0; $$ = $2;}
OPT_ID: ID
| {$$.p = (void*)NULL;}
;
ID: {only_id = 1;} Y_ID {only_id = 0; $$ = $2;}
%%
/* Maintain and update the address of labels for the current line. */
void
fix_current_label_address (mem_addr new_addr)
{
label_list *l;
for (l = this_line_labels; l != NULL; l = l->tail)
{
l->head->addr = new_addr;
}
clear_labels ();
}
static label_list *
cons_label (label *head, label_list *tail)
{
label_list *c = (label_list *) malloc (sizeof (label_list));
c->head = head;
c->tail = tail;
return (c);
}
static void
clear_labels ()
{
label_list *n;
for ( ; this_line_labels != NULL; this_line_labels = n)
{
resolve_label_uses (this_line_labels->head);
n = this_line_labels->tail;
free (this_line_labels);
}
this_line_labels = NULL;
}
/* Operations on op codes. */
int
op_to_imm_op (int opcode)
{
switch (opcode)
{
case Y_ADD_OP: return (Y_ADDI_OP);
case Y_ADDU_OP: return (Y_ADDIU_OP);
case Y_AND_OP: return (Y_ANDI_OP);
case Y_OR_OP: return (Y_ORI_OP);
case Y_XOR_OP: return (Y_XORI_OP);
case Y_SLT_OP: return (Y_SLTI_OP);
case Y_SLTU_OP: return (Y_SLTIU_OP);
case Y_SLLV_OP: return (Y_SLL_OP);
case Y_SRAV_OP: return (Y_SRA_OP);
case Y_SRLV_OP: return (Y_SRL_OP);
default: fatal_error ("Can't convert op to immediate op\n"); return (0);
}
}
int
imm_op_to_op (int opcode)
{
switch (opcode)
{
case Y_ADDI_OP: return (Y_ADD_OP);
case Y_ADDIU_OP: return (Y_ADDU_OP);
case Y_ANDI_OP: return (Y_AND_OP);
case Y_ORI_OP: return (Y_OR_OP);
case Y_XORI_OP: return (Y_XOR_OP);
case Y_SLTI_OP: return (Y_SLT_OP);
case Y_SLTIU_OP: return (Y_SLTU_OP);
case Y_J_OP: return (Y_JR_OP);
case Y_LUI_OP: return (Y_ADDU_OP);
case Y_SLL_OP: return (Y_SLLV_OP);
case Y_SRA_OP: return (Y_SRAV_OP);
case Y_SRL_OP: return (Y_SRLV_OP);
default: fatal_error ("Can't convert immediate op to op\n"); return (0);
}
}
static void
nop_inst ()
{
r_type_inst (Y_SLL_OP, 0, 0, 0); /* = 0 */
}
static void
trap_inst ()
{
r_type_inst (Y_BREAK_OP, 0, 0, 0);
}
static imm_expr *
branch_offset (int n_inst)
{
return (const_imm_expr (n_inst << 2)); /* Later shifted right 2 places */
}
static void
div_inst (int op, int rd, int rs, int rt, int const_divisor)
{
if (rd != 0 && !const_divisor)
{
i_type_inst_free (Y_BNE_OP, 0, rt, branch_offset (2));
trap_inst ();
}
if (op == Y_DIV_OP || op == Y_REM_POP)
r_type_inst (Y_DIV_OP, 0, rs, rt);
else
r_type_inst (Y_DIVU_OP, 0, rs, rt);
if (rd != 0)
{
if (op == Y_DIV_OP || op == Y_DIVU_OP)
/* Quotient */
r_type_inst (Y_MFLO_OP, rd, 0, 0);
else
/* Remainder */
r_type_inst (Y_MFHI_OP, rd, 0, 0);
}
}
static void
mult_inst (int op, int rd, int rs, int rt)
{
if (op == Y_MULOU_POP)
r_type_inst (Y_MULTU_OP, 0, rs, rt);
else
r_type_inst (Y_MULT_OP, 0, rs, rt);
if (op == Y_MULOU_POP && rd != 0)
{
r_type_inst (Y_MFHI_OP, 1, 0, 0); /* Use $at */
i_type_inst_free (Y_BEQ_OP, 0, 1, branch_offset (2));
trap_inst ();
}
else if (op == Y_MULO_POP && rd != 0)
{
r_type_inst (Y_MFHI_OP, 1, 0, 0); /* use $at */
r_type_inst (Y_MFLO_OP, rd, 0, 0);
r_sh_type_inst (Y_SRA_OP, rd, rd, 31);
i_type_inst_free (Y_BEQ_OP, rd, 1, branch_offset (2));
trap_inst ();
}
if (rd != 0)
r_type_inst (Y_MFLO_OP, rd, 0, 0);
}
static void
set_le_inst (int op, int rd, int rs, int rt)
{
i_type_inst_free (Y_BNE_OP, rs, rt, branch_offset (3));
i_type_inst_free (Y_ORI_OP, rd, 0, const_imm_expr (1));
i_type_inst_free (Y_BEQ_OP, 0, 0, branch_offset (2));
r_type_inst ((op == Y_SLE_POP ? Y_SLT_OP : Y_SLTU_OP), rd, rs, rt);
}
static void
set_gt_inst (int op, int rd, int rs, int rt)
{
r_type_inst (op == Y_SGT_POP ? Y_SLT_OP : Y_SLTU_OP, rd, rt, rs);
}
static void
set_ge_inst (int op, int rd, int rs, int rt)
{
i_type_inst_free (Y_BNE_OP, rs, rt, branch_offset (3));
i_type_inst_free (Y_ORI_OP, rd, 0, const_imm_expr (1));
i_type_inst_free (Y_BEQ_OP, 0, 0, branch_offset (2));
r_type_inst (op == Y_SGE_POP ? Y_SLT_OP : Y_SLTU_OP, rd, rt, rs);
}
static void
set_eq_inst (int op, int rd, int rs, int rt)
{
imm_expr *if_eq, *if_neq;
if (op == Y_SEQ_POP)
if_eq = const_imm_expr (1), if_neq = const_imm_expr (0);
else
if_eq = const_imm_expr (0), if_neq = const_imm_expr (1);
i_type_inst_free (Y_BEQ_OP, rs, rt, branch_offset (3));
/* RD <- 0 (if not equal) */
i_type_inst_free (Y_ORI_OP, rd, 0, if_neq);
i_type_inst_free (Y_BEQ_OP, 0, 0, branch_offset (2)); /* Branch always */
/* RD <- 1 */
i_type_inst_free (Y_ORI_OP, rd, 0, if_eq);
}
/* Store the value either as a datum or instruction. */
static void
store_word_data (int value)
{
if (data_dir)
store_word (value);
else if (text_dir)
store_instruction (inst_decode (value));
}
void
initialize_parser (char *file_name)
{
input_file_name = file_name;
only_id = 0;
data_dir = 0;
text_dir = 1;
}
static void
check_imm_range (imm_expr* expr, int32 min, int32 max)
{
if (expr->symbol == NULL || SYMBOL_IS_DEFINED (expr->symbol))
{
/* If expression can be evaluated, compare its value against the limits
and complain if the value is out of bounds. */
int32 value = eval_imm_expr (expr);
if (value < min || max < value)
{
char str[200];
sprintf (str, "immediate value (%d) out of range (%d .. %d)",
value, min, max);
yywarn (str);
}
}
}
static void
check_uimm_range (imm_expr* expr, uint32 min, uint32 max)
{
if (expr->symbol == NULL || SYMBOL_IS_DEFINED (expr->symbol))
{
/* If expression can be evaluated, compare its value against the limits
and complain if the value is out of bounds. */
uint32 value = (uint32)eval_imm_expr (expr);
if (value < min || max < value)
{
char str[200];
sprintf (str, "immediate value (%d) out of range (%d .. %d)",
(int32)value, (int32)min, (int32)max);
yywarn (str);
}
}
}
void
yyerror (char *s)
{
parse_error_occurred = 1;
clear_labels ();
yywarn (s);
}
void
yywarn (char *s)
{
error ("spim: (parser) %s on line %d of file %s\n", s, line_no, input_file_name);
print_erroneous_line ();
}
static void
mips32_r2_inst ()
{
yyerror ("Warning: MIPS32 Rev 2 instruction is not implemented. Instruction ignored.");
}
static int
cc_to_rt (int cc, int nd, int tf)
{
return (cc << 2) | (nd << 1) | tf;
}
|