OLD | NEW |
1 // Derived from Inferno utils/6c/txt.c | 1 // Derived from Inferno utils/6c/txt.c |
2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/txt.c | 2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/txt.c |
3 // | 3 // |
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. | 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) | 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) |
6 // Portions Copyright © 1997-1999 Vita Nuova Limited | 6 // Portions Copyright © 1997-1999 Vita Nuova Limited |
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) | 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) |
8 // Portions Copyright © 2004,2006 Bruce Ellis | 8 // Portions Copyright © 2004,2006 Bruce Ellis |
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) | 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) |
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others | 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others |
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 case ODOT: | 1702 case ODOT: |
1703 case ODOTPTR: | 1703 case ODOTPTR: |
1704 cleani += 2; | 1704 cleani += 2; |
1705 reg = &clean[cleani-1]; | 1705 reg = &clean[cleani-1]; |
1706 reg1 = &clean[cleani-2]; | 1706 reg1 = &clean[cleani-2]; |
1707 reg->op = OEMPTY; | 1707 reg->op = OEMPTY; |
1708 reg1->op = OEMPTY; | 1708 reg1->op = OEMPTY; |
1709 goto odot; | 1709 goto odot; |
1710 | 1710 |
1711 case OINDEX: | 1711 case OINDEX: |
1712 cleani += 2; | |
1713 reg = &clean[cleani-1]; | |
1714 reg1 = &clean[cleani-2]; | |
1715 reg->op = OEMPTY; | |
1716 reg1->op = OEMPTY; | |
1717 goto oindex; | 1712 goto oindex; |
1718 } | 1713 } |
1719 return 0; | 1714 return 0; |
1720 | 1715 |
1721 lit: | 1716 lit: |
1722 switch(as) { | 1717 switch(as) { |
1723 default: | 1718 default: |
1724 return 0; | 1719 return 0; |
1725 case AADDB: case AADDW: case AADDL: case AADDQ: | 1720 case AADDB: case AADDW: case AADDL: case AADDQ: |
1726 case ASUBB: case ASUBW: case ASUBL: case ASUBQ: | 1721 case ASUBB: case ASUBW: case ASUBL: case ASUBQ: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 | 1770 |
1776 a->type = D_NONE; | 1771 a->type = D_NONE; |
1777 a->index = D_NONE; | 1772 a->index = D_NONE; |
1778 naddr(&n1, a, 1); | 1773 naddr(&n1, a, 1); |
1779 goto yes; | 1774 goto yes; |
1780 | 1775 |
1781 oindex: | 1776 oindex: |
1782 l = n->left; | 1777 l = n->left; |
1783 r = n->right; | 1778 r = n->right; |
1784 if(l->ullman >= UINF && r->ullman >= UINF) | 1779 if(l->ullman >= UINF && r->ullman >= UINF) |
1785 » » goto no; | 1780 » » return 0; |
1786 | 1781 |
1787 // set o to type of array | 1782 // set o to type of array |
1788 o = 0; | 1783 o = 0; |
1789 if(isptr[l->type->etype]) | 1784 if(isptr[l->type->etype]) |
1790 fatal("ptr ary"); | 1785 fatal("ptr ary"); |
1791 if(l->type->etype != TARRAY) | 1786 if(l->type->etype != TARRAY) |
1792 fatal("not ary"); | 1787 fatal("not ary"); |
1793 if(l->type->bound < 0) | 1788 if(l->type->bound < 0) |
1794 o += ODynam; | 1789 o += ODynam; |
1795 | 1790 |
1796 w = n->type->width; | 1791 w = n->type->width; |
1797 if(isconst(r, CTINT)) | 1792 if(isconst(r, CTINT)) |
1798 goto oindex_const; | 1793 goto oindex_const; |
1799 | 1794 |
1800 switch(w) { | 1795 switch(w) { |
1801 default: | 1796 default: |
1802 » » goto no; | 1797 » » return 0; |
1803 case 1: | 1798 case 1: |
1804 case 2: | 1799 case 2: |
1805 case 4: | 1800 case 4: |
1806 case 8: | 1801 case 8: |
1807 break; | 1802 break; |
1808 } | 1803 } |
1809 | 1804 |
| 1805 // if(sudoaddable(as, l, a)) |
| 1806 // goto oindex_sudo; |
| 1807 |
| 1808 cleani += 2; |
| 1809 reg = &clean[cleani-1]; |
| 1810 reg1 = &clean[cleani-2]; |
| 1811 reg->op = OEMPTY; |
| 1812 reg1->op = OEMPTY; |
| 1813 |
1810 // load the array (reg) | 1814 // load the array (reg) |
1811 if(l->ullman > r->ullman) { | 1815 if(l->ullman > r->ullman) { |
1812 regalloc(reg, types[tptr], N); | 1816 regalloc(reg, types[tptr], N); |
1813 agen(l, reg); | 1817 agen(l, reg); |
1814 } | 1818 } |
1815 | 1819 |
1816 // load the index (reg1) | 1820 // load the index (reg1) |
1817 t = types[TUINT64]; | 1821 t = types[TUINT64]; |
1818 if(issigned[r->type->etype]) | 1822 if(issigned[r->type->etype]) |
1819 t = types[TINT64]; | 1823 t = types[TINT64]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 a->index = a->type; | 1873 a->index = a->type; |
1870 a->type = reg->val.u.reg + D_INDIR; | 1874 a->type = reg->val.u.reg + D_INDIR; |
1871 | 1875 |
1872 goto yes; | 1876 goto yes; |
1873 | 1877 |
1874 oindex_const: | 1878 oindex_const: |
1875 // index is constant | 1879 // index is constant |
1876 // can check statically and | 1880 // can check statically and |
1877 // can multiply by width statically | 1881 // can multiply by width statically |
1878 | 1882 |
| 1883 if((o & ODynam) == 0) |
| 1884 if(sudoaddable(as, l, a)) |
| 1885 goto oindex_const_sudo; |
| 1886 |
| 1887 cleani += 2; |
| 1888 reg = &clean[cleani-1]; |
| 1889 reg1 = &clean[cleani-2]; |
| 1890 reg->op = OEMPTY; |
| 1891 reg1->op = OEMPTY; |
| 1892 |
1879 regalloc(reg, types[tptr], N); | 1893 regalloc(reg, types[tptr], N); |
1880 agen(l, reg); | 1894 agen(l, reg); |
1881 | 1895 |
1882 v = mpgetfix(r->val.u.xval); | 1896 v = mpgetfix(r->val.u.xval); |
1883 if(o & ODynam) { | 1897 if(o & ODynam) { |
1884 | |
1885 if(!debug['B'] && !n->etype) { | 1898 if(!debug['B'] && !n->etype) { |
1886 n1 = *reg; | 1899 n1 = *reg; |
1887 n1.op = OINDREG; | 1900 n1.op = OINDREG; |
1888 n1.type = types[tptr]; | 1901 n1.type = types[tptr]; |
1889 n1.xoffset = Array_nel; | 1902 n1.xoffset = Array_nel; |
1890 nodconst(&n2, types[TUINT64], v); | 1903 nodconst(&n2, types[TUINT64], v); |
1891 gins(optoas(OCMP, types[TUINT32]), &n1, &n2); | 1904 gins(optoas(OCMP, types[TUINT32]), &n1, &n2); |
1892 p1 = gbranch(optoas(OGT, types[TUINT32]), T); | 1905 p1 = gbranch(optoas(OGT, types[TUINT32]), T); |
1893 ginscall(throwindex, 0); | 1906 ginscall(throwindex, 0); |
1894 patch(p1, pc); | 1907 patch(p1, pc); |
(...skipping 16 matching lines...) Expand all Loading... |
1911 } | 1924 } |
1912 | 1925 |
1913 n2 = *reg; | 1926 n2 = *reg; |
1914 n2.op = OINDREG; | 1927 n2.op = OINDREG; |
1915 n2.xoffset = v*w; | 1928 n2.xoffset = v*w; |
1916 a->type = D_NONE; | 1929 a->type = D_NONE; |
1917 a->index = D_NONE; | 1930 a->index = D_NONE; |
1918 naddr(&n2, a, 1); | 1931 naddr(&n2, a, 1); |
1919 goto yes; | 1932 goto yes; |
1920 | 1933 |
| 1934 oindex_const_sudo: |
| 1935 v = mpgetfix(r->val.u.xval); |
| 1936 if(v < 0) { |
| 1937 yyerror("out of bounds on array"); |
| 1938 } else |
| 1939 if(v >= l->type->bound) { |
| 1940 yyerror("out of bounds on array"); |
| 1941 } |
| 1942 a->offset += v*w; |
| 1943 goto yes; |
| 1944 |
1921 yes: | 1945 yes: |
1922 return 1; | 1946 return 1; |
1923 | 1947 |
1924 no: | 1948 no: |
1925 sudoclean(); | 1949 sudoclean(); |
1926 return 0; | 1950 return 0; |
1927 } | 1951 } |
OLD | NEW |