History

parsing optimizations

bellard committed 23 years ago

Commit 8901fbe1 parent b81d4ba2 files · +316 −215Browse files

Unified · Split

2 files
  1. tcc.c +315 −214
  2. tccelf.c +1 −1
tcc.c+315−214
@@ -1118,11 +1118,13 @@ void test_lvalue(void) · 1117 unmodified lines
1118TokenSym *tok_alloc(const char *str, int len)1118TokenSym *tok_alloc(const char *str, int len)
1119{1119{
1120 TokenSym *ts, **pts, **ptable;1120 TokenSym *ts, **pts, **ptable;
1121 int h, i;1121 int i;
1122 unsigned int h;
1122 1123
1123 h = 1;1124 h = 1;
1124 for(i=0;i<len;i++)1125 for(i=0;i<len;i++)
1125 h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1);1126 h = h * 263 + ((unsigned char *)str)[i];
1127 h &= (TOK_HASH_SIZE - 1);
1126 1128
1127 pts = &hash_ident[h];1129 pts = &hash_ident[h];
1128 while (1) {1130 while (1) {
@@ -1522,7 +1524,12 @@ static int tcc_peekc_slow(BufferedFile *bf) · 393 unmodified lines
1522 /* only tries to read if really end of buffer */1524 /* only tries to read if really end of buffer */
1523 if (bf->buf_ptr >= bf->buf_end) {1525 if (bf->buf_ptr >= bf->buf_end) {
1524 if (bf->fd != -1) {1526 if (bf->fd != -1) {
1525 len = read(bf->fd, bf->buffer, IO_BUF_SIZE);1527#if defined(PARSE_DEBUG)
1528 len = 8;
1529#else
1530 len = IO_BUF_SIZE;
1531#endif
1532 len = read(bf->fd, bf->buffer, len);
1526 if (len < 0)1533 if (len < 0)
1527 len = 0;1534 len = 0;
1528 } else {1535 } else {
@@ -1541,13 +1548,11 @@ static int tcc_peekc_slow(BufferedFile *bf) · 12 unmodified lines
1541 }1548 }
1542}1549}
1543 1550
1544/* no need to put that inline */1551/* return the current character, handling end of block if necessary
1545void handle_eob(void)1552 (but not stray) */
1553static int handle_eob(void)
1546{1554{
1547 /* no need to do anything if not at EOB */1555 return tcc_peekc_slow(file);
1548 if (file->buf_ptr < file->buf_end)
1549 return;
1550 ch = tcc_peekc_slow(file);
1551}1556}
1552 1557
1553/* read next char from current input file and handle end of input buffer */1558/* read next char from current input file and handle end of input buffer */
@@ -1556,7 +1561,7 @@ static inline void inp(void) · 2 unmodified lines
1556 ch = *(++(file->buf_ptr));1561 ch = *(++(file->buf_ptr));
1557 /* end of buffer/file handling */1562 /* end of buffer/file handling */
1558 if (ch == CH_EOB)1563 if (ch == CH_EOB)
1559 handle_eob();1564 ch = handle_eob();
1560}1565}
1561 1566
1562/* handle '\[\r]\n' */1567/* handle '\[\r]\n' */
@@ -1580,6 +1585,40 @@ static void handle_stray(void) · 17 unmodified lines
1580 }1585 }
1581}1586}
1582 1587
1588/* skip the stray and handle the \\n case. Output an error if
1589 incorrect char after the stray */
1590static int handle_stray1(uint8_t *p)
1591{
1592 int c;
1593
1594 if (p >= file->buf_end) {
1595 file->buf_ptr = p;
1596 c = handle_eob();
1597 p = file->buf_ptr;
1598 if (c == '\\')
1599 goto parse_stray;
1600 } else {
1601 parse_stray:
1602 file->buf_ptr = p;
1603 ch = *p;
1604 handle_stray();
1605 p = file->buf_ptr;
1606 c = *p;
1607 }
1608 return c;
1609}
1610
1611/* handle the complicated stray case */
1612#define PEEKC(c, p)\
1613{\
1614 p++;\
1615 c = *p;\
1616 if (c == '\\') {\
1617 c = handle_stray1(p);\
1618 p = file->buf_ptr;\
1619 }\
1620}
1621
1583/* input with '\[\r]\n' handling. Note that this function cannot1622/* input with '\[\r]\n' handling. Note that this function cannot
1584 handle other characters after '\', so you cannot call it inside1623 handle other characters after '\', so you cannot call it inside
1585 strings or comments */1624 strings or comments */
@@ -1606,8 +1645,8 @@ static void parse_comment(void) · 20 unmodified lines
1606 int c;1645 int c;
1607 1646
1608 /* C comments */1647 /* C comments */
1609 minp();
1610 p = file->buf_ptr;1648 p = file->buf_ptr;
1649 p++;
1611 for(;;) {1650 for(;;) {
1612 /* fast skip loop */1651 /* fast skip loop */
1613 for(;;) {1652 for(;;) {
@@ -1628,49 +1667,49 @@ static void parse_comment(void) · 14 unmodified lines
1628 p++;1667 p++;
1629 for(;;) {1668 for(;;) {
1630 c = *p;1669 c = *p;
1631 if (c == '/') {1670 if (c == '*') {
1671 p++;
1672 } else if (c == '/') {
1632 goto end_of_comment;1673 goto end_of_comment;
1633 } else if (c == '\\') {1674 } else if (c == '\\') {
1634 if (p >= file->buf_end) {1675 file->buf_ptr = p;
1635 file->buf_ptr = p;1676 c = handle_eob();
1636 handle_eob();1677 if (c == '\\') {
1637 p = file->buf_ptr;1678 /* skip '\\n', but if '\' followed but another
1638 if (p >= file->buf_end)1679 char, behave asif a stray was parsed */
1639 goto eof_found;1680 ch = file->buf_ptr[0];
1640 continue;1681 while (ch == '\\') {
1641 }1682 inp();
1642 p++;1683 if (ch == '\n') {
1643 c = *p;1684 file->line_num++;
1644 if (c == '\n') {1685 inp();
1645 file->line_num++;1686 } else if (ch == '\r') {
1646 p++;1687 inp();
1647 } else if (c == '\r') {1688 if (ch == '\n') {
1648 p++;1689 file->line_num++;
1649 c = *p;1690 inp();
1650 if (c != '\n')1691 }
1651 break;1692 } else {
1652 file->line_num++;1693 p = file->buf_ptr;
1653 p++;1694 break;
1654 } else {1695 }
1655 break;1696 }
1656 }1697 }
1657 } else if (c == '*') {1698 p = file->buf_ptr;
1658 p++;
1659 } else {1699 } else {
1660 break;1700 break;
1661 }1701 }
1662 }1702 }
1663 } else if (p >= file->buf_end) {1703 } else {
1704 /* stray, eob or eof */
1664 file->buf_ptr = p;1705 file->buf_ptr = p;
1665 handle_eob();1706 c = handle_eob();
1666 p = file->buf_ptr;1707 p = file->buf_ptr;
1667 if (p >= file->buf_end) {1708 if (c == CH_EOF) {
1668 eof_found:
1669 error("unexpected end of file in comment");1709 error("unexpected end of file in comment");
1710 } else if (c == '\\') {
1711 p++;
1670 }1712 }
1671 } else {
1672 /* stray */
1673 p++;
1674 }1713 }
1675 }1714 }
1676 end_of_comment:1715 end_of_comment:
@@ -1697,63 +1736,98 @@ static inline void skip_spaces(void) · 20 unmodified lines
1697 #if/#endif */1736 #if/#endif */
1698void preprocess_skip(void)1737void preprocess_skip(void)
1699{1738{
1700 int a, start_of_line, sep;1739 int a, start_of_line, sep, c;
1701 1740 uint8_t *p;
1741
1742 p = file->buf_ptr;
1702 start_of_line = 1;1743 start_of_line = 1;
1703 a = 0;1744 a = 0;
1704 for(;;) {1745 for(;;) {
1705 redo_no_start:1746 redo_no_start:
1706 switch(ch) {1747 c = *p;
1748 switch(c) {
1707 case ' ':1749 case ' ':
1708 case '\t':1750 case '\t':
1709 case '\f':1751 case '\f':
1710 case '\v':1752 case '\v':
1711 case '\r':1753 case '\r':
1712 inp();1754 p++;
1713 goto redo_no_start;1755 goto redo_no_start;
1714 case '\n':1756 case '\n':
1715 start_of_line = 1;1757 start_of_line = 1;
1716 file->line_num++;1758 file->line_num++;
1717 inp();1759 p++;
1718 goto redo_no_start;1760 goto redo_no_start;
1719 case '\\':1761 case '\\':
1720 handle_stray();1762 file->buf_ptr = p;
1763 c = handle_eob();
1764 if (c == CH_EOF) {
1765 expect("#endif");
1766 } else if (c == '\\') {
1767 /* XXX: incorrect: should not give an error */
1768 ch = file->buf_ptr[0];
1769 handle_stray();
1770 }
1771 p = file->buf_ptr;
1721 goto redo_no_start;1772 goto redo_no_start;
1722 /* skip strings */1773 /* skip strings */
1723 case '\"':1774 case '\"':
1724 case '\'':1775 case '\'':
1725 sep = ch;1776 sep = c;
1726 inp();1777 p++;
1727 while (ch != sep) {1778 for(;;) {
1728 /* XXX: better error message */1779 c = *p;
1729 if (ch == TOK_EOF) {1780 if (c == sep) {
1730 error("unterminated string");1781 break;
1731 } else if (ch == '\n') {1782 } else if (c == '\\') {
1783 file->buf_ptr = p;
1784 c = handle_eob();
1785 p = file->buf_ptr;
1786 if (c == CH_EOF) {
1787 /* XXX: better error message */
1788 error("unterminated string");
1789 } else if (c == '\\') {
1790 /* ignore next char */
1791 p++;
1792 c = *p;
1793 if (c == '\\') {
1794 file->buf_ptr = p;
1795 c = handle_eob();
1796 p = file->buf_ptr;
1797 }
1798 if (c == '\n')
1799 file->line_num++;
1800 else if (c != CH_EOF)
1801 p++;
1802 }
1803 } else if (c == '\n') {
1732 file->line_num++;1804 file->line_num++;
1733 } else if (ch == '\\') {1805 p++;
1734 /* ignore next char */1806 } else {
1735 inp();1807 p++;
1736 if (ch == '\n')
1737 file->line_num++;
1738 }1808 }
1739 inp();
1740 }1809 }
1741 minp();1810 p++;
1742 break;1811 break;
1743 /* skip comments */1812 /* skip comments */
1744 case '/':1813 case '/':
1814 file->buf_ptr = p;
1815 ch = *p;
1745 minp();1816 minp();
1746 if (ch == '*') {1817 if (ch == '*') {
1747 parse_comment();1818 parse_comment();
1748 } else if (ch == '/') {1819 } else if (ch == '/') {
1749 parse_line_comment();1820 parse_line_comment();
1750 }1821 }
1822 p = file->buf_ptr;
1751 break;1823 break;
1752 1824
1753 case '#':1825 case '#':
1754 minp();1826 p++;
1755 if (start_of_line) {1827 if (start_of_line) {
1828 file->buf_ptr = p;
1756 next_nomacro();1829 next_nomacro();
1830 p = file->buf_ptr;
1757 if (a == 0 && 1831 if (a == 0 &&
1758 (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF))1832 (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF))
1759 goto the_end;1833 goto the_end;
@@ -1763,16 +1837,14 @@ void preprocess_skip(void) · 3 unmodified lines
1763 a--;1837 a--;
1764 }1838 }
1765 break;1839 break;
1766 case CH_EOF:
1767 expect("#endif");
1768 break;
1769 default:1840 default:
1770 inp();1841 p++;
1771 break;1842 break;
1772 }1843 }
1773 start_of_line = 0;1844 start_of_line = 0;
1774 }1845 }
1775 the_end: ;1846 the_end: ;
1847 file->buf_ptr = p;
1776}1848}
1777 1849
1778/* ParseState handling */1850/* ParseState handling */
@@ -2040,10 +2112,10 @@ void tok_print(int *str) · 261 unmodified lines
2040#endif2112#endif
2041 2113
2042/* parse after #define */2114/* parse after #define */
2043void parse_define(void)2115static void parse_define(void)
2044{2116{
2045 Sym *s, *first, **ps;2117 Sym *s, *first, **ps;
2046 int v, t, varg, is_vaargs;2118 int v, t, varg, is_vaargs, c;
2047 TokenString str;2119 TokenString str;
2048 2120
2049 v = tok;2121 v = tok;
@@ -2053,7 +2125,10 @@ void parse_define(void) · 3 unmodified lines
2053 first = NULL;2125 first = NULL;
2054 t = MACRO_OBJ;2126 t = MACRO_OBJ;
2055 /* '(' must be just after macro definition for MACRO_FUNC */2127 /* '(' must be just after macro definition for MACRO_FUNC */
2056 if (ch == '(') {2128 c = file->buf_ptr[0];
2129 if (c == '\\')
2130 c = handle_stray1(file->buf_ptr);
2131 if (c == '(') {
2057 next_nomacro();2132 next_nomacro();
2058 next_nomacro();2133 next_nomacro();
2059 ps = &first;2134 ps = &first;
@@ -2156,6 +2231,8 @@ static void preprocess(int is_bof) · 96 unmodified lines
2156 define_undef(s);2231 define_undef(s);
2157 break;2232 break;
2158 case TOK_INCLUDE:2233 case TOK_INCLUDE:
2234 ch = file->buf_ptr[0];
2235 /* XXX: incorrect if comments : use next_nomacro with a special mode */
2159 skip_spaces();2236 skip_spaces();
2160 if (ch == '<') {2237 if (ch == '<') {
2161 c = '>';2238 c = '>';
@@ -2781,32 +2858,55 @@ void parse_number(const char *p) · 619 unmodified lines
2781 }2858 }
2782}2859}
2783 2860
2861
2862#define PARSE2(c1, tok1, c2, tok2) \
2863 case c1: \
2864 PEEKC(c, p); \
2865 if (c == c2) { \
2866 p++; \
2867 tok = tok2; \
2868 } else { \
2869 tok = tok1; \
2870 } \
2871 break;
2872
2784/* return next token without macro substitution */2873/* return next token without macro substitution */
2785static inline void next_nomacro1(void)2874static inline void next_nomacro1(void)
2786{2875{
2787 int b, t;2876 int b, t, c;
2788 char *q;
2789 TokenSym *ts;2877 TokenSym *ts;
2878 uint8_t *p, *p1;
2790 2879
2880 p = file->buf_ptr;
2791 redo_no_start:2881 redo_no_start:
2792 switch(ch) {2882 c = *p;
2883 switch(c) {
2793 case ' ':2884 case ' ':
2794 case '\t':2885 case '\t':
2795 case '\f':2886 case '\f':
2796 case '\v':2887 case '\v':
2797 case '\r':2888 case '\r':
2798 inp();2889 p++;
2799 goto redo_no_start;2890 goto redo_no_start;
2800 2891
2801 case '\\':2892 case '\\':
2802 /* first look if it is in fact an end of buffer */2893 /* first look if it is in fact an end of buffer */
2803 handle_eob();2894 if (p >= file->buf_end) {
2804 if (ch != '\\')2895 file->buf_ptr = p;
2896 handle_eob();
2897 p = file->buf_ptr;
2898 if (p >= file->buf_end)
2899 goto parse_eof;
2900 else
2901 goto redo_no_start;
2902 } else {
2903 file->buf_ptr = p;
2904 ch = *p;
2905 handle_stray();
2906 p = file->buf_ptr;
2805 goto redo_no_start;2907 goto redo_no_start;
2806 handle_stray();2908 }
2807 goto redo_no_start;2909 parse_eof:
2808
2809 case CH_EOF:
2810 {2910 {
2811 TCCState *s1 = tcc_state;2911 TCCState *s1 = tcc_state;
2812 2912
@@ -2837,6 +2937,7 @@ static inline void next_nomacro1(void) · 24 unmodified lines
2837 s1->include_stack_ptr--;2937 s1->include_stack_ptr--;
2838 file = *s1->include_stack_ptr;2938 file = *s1->include_stack_ptr;
2839 inp();2939 inp();
2940 p = file->buf_ptr;
2840 goto redo_no_start;2941 goto redo_no_start;
2841 }2942 }
2842 }2943 }
@@ -2848,19 +2949,22 @@ static inline void next_nomacro1(void) · 5 unmodified lines
2848 tok = TOK_LINEFEED;2949 tok = TOK_LINEFEED;
2849 } else {2950 } else {
2850 tok_flags |= TOK_FLAG_BOL;2951 tok_flags |= TOK_FLAG_BOL;
2851 inp();2952 p++;
2852 goto redo_no_start;2953 goto redo_no_start;
2853 }2954 }
2854 break;2955 break;
2855 2956
2856 case '#':2957 case '#':
2857 minp();2958 /* XXX: simplify */
2959 PEEKC(c, p);
2858 if (tok_flags & TOK_FLAG_BOL) {2960 if (tok_flags & TOK_FLAG_BOL) {
2961 file->buf_ptr = p;
2859 preprocess(tok_flags & TOK_FLAG_BOF);2962 preprocess(tok_flags & TOK_FLAG_BOF);
2963 p = file->buf_ptr;
2860 goto redo_no_start;2964 goto redo_no_start;
2861 } else {2965 } else {
2862 if (ch == '#') {2966 if (c == '#') {
2863 inp();2967 p++;
2864 tok = TOK_TWOSHARPS;2968 tok = TOK_TWOSHARPS;
2865 } else {2969 } else {
2866 tok = '#';2970 tok = '#';
@@ -2883,34 +2987,57 @@ static inline void next_nomacro1(void) · 16 unmodified lines
2883 case 'U': case 'V': case 'W': case 'X':2987 case 'U': case 'V': case 'W': case 'X':
2884 case 'Y': case 'Z': 2988 case 'Y': case 'Z':
2885 case '_':2989 case '_':
2886 q = token_buf;2990 parse_ident_fast:
2887 *q++ = ch;2991 p1 = p;
2888 cinp();2992 p++;
2889 parse_ident:2993 for(;;) {
2890 while (isid(ch) || isnum(ch)) {2994 c = *p;
2891 if (q >= token_buf + STRING_MAX_SIZE)2995 if (!isid(c) && !isnum(c))
2892 error("ident too long");2996 break;
2893 *q++ = ch;2997 p++;
2894 cinp();2998 }
2999 if (c != '\\') {
3000 /* fast case : no stray found, so we have the full token */
3001 ts = tok_alloc(p1, p - p1);
3002 } else {
3003 /* slower case */
3004 cstr_reset(&tokcstr);
3005
3006 while (p1 < p) {
3007 cstr_ccat(&tokcstr, *p1);
3008 p1++;
3009 }
3010 p--;
3011 PEEKC(c, p);
3012 parse_ident_slow:
3013 while (isid(c) || isnum(c)) {
3014 cstr_ccat(&tokcstr, c);
3015 PEEKC(c, p);
3016 }
3017 ts = tok_alloc(tokcstr.data, tokcstr.size);
2895 }3018 }
2896 *q = '\0';
2897 ts = tok_alloc(token_buf, q - token_buf);
2898 tok = ts->tok;3019 tok = ts->tok;
2899 break;3020 break;
2900 case 'L':3021 case 'L':
2901 minp();3022 c = p[1];
2902 if (ch == '\'') {3023 if (c != '\\' && c != '\'' && c != '\"') {
2903 tok = TOK_LCHAR;3024 /* fast case */
2904 goto char_const;3025 goto parse_ident_fast;
2905 }3026 } else {
2906 if (ch == '\"') {3027 PEEKC(c, p);
2907 tok = TOK_LSTR;3028 if (c == '\'') {
2908 goto str_const;3029 tok = TOK_LCHAR;
3030 goto char_const;
3031 } else if (c == '\"') {
3032 tok = TOK_LSTR;
3033 goto str_const;
3034 } else {
3035 cstr_reset(&tokcstr);
3036 cstr_ccat(&tokcstr, 'L');
3037 goto parse_ident_slow;
3038 }
2909 }3039 }
2910 q = token_buf;3040 break;
2911 *q++ = 'L';
2912 goto parse_ident;
2913
2914 case '0': case '1': case '2': case '3':3041 case '0': case '1': case '2': case '3':
2915 case '4': case '5': case '6': case '7':3042 case '4': case '5': case '6': case '7':
2916 case '8': case '9':3043 case '8': case '9':
@@ -2920,11 +3047,11 @@ static inline void next_nomacro1(void) · 3 unmodified lines
2920 prefixed by 'eEpP' */3047 prefixed by 'eEpP' */
2921 parse_num:3048 parse_num:
2922 for(;;) {3049 for(;;) {
2923 t = ch;3050 t = c;
2924 cstr_ccat(&tokcstr, ch);3051 cstr_ccat(&tokcstr, c);
2925 cinp();3052 PEEKC(c, p);
2926 if (!(isnum(ch) || isid(ch) || ch == '.' ||3053 if (!(isnum(c) || isid(c) || c == '.' ||
2927 ((ch == '+' || ch == '-') && 3054 ((c == '+' || c == '-') &&
2928 (t == 'e' || t == 'E' || t == 'p' || t == 'P'))))3055 (t == 'e' || t == 'E' || t == 'p' || t == 'P'))))
2929 break;3056 break;
2930 }3057 }
@@ -2935,17 +3062,16 @@ static inline void next_nomacro1(void) · 4 unmodified lines
2935 break;3062 break;
2936 case '.':3063 case '.':
2937 /* special dot handling because it can also start a number */3064 /* special dot handling because it can also start a number */
2938 cinp();3065 PEEKC(c, p);
2939 if (isnum(ch)) {3066 if (isnum(c)) {
2940 cstr_reset(&tokcstr);3067 cstr_reset(&tokcstr);
2941 cstr_ccat(&tokcstr, '.');3068 cstr_ccat(&tokcstr, '.');
2942 goto parse_num;3069 goto parse_num;
2943 }3070 } else if (c == '.') {
2944 if (ch == '.') {3071 PEEKC(c, p);
2945 cinp();3072 if (c != '.')
2946 if (ch != '.')
2947 expect("'.'");3073 expect("'.'");
2948 cinp();3074 PEEKC(c, p);
2949 tok = TOK_DOTS;3075 tok = TOK_DOTS;
2950 } else {3076 } else {
2951 tok = '.';3077 tok = '.';
@@ -2954,6 +3080,7 @@ static inline void next_nomacro1(void) · 2 unmodified lines
2954 case '\'':3080 case '\'':
2955 tok = TOK_CCHAR;3081 tok = TOK_CCHAR;
2956 char_const:3082 char_const:
3083 file->buf_ptr = p;
2957 inp();3084 inp();
2958 b = getq();3085 b = getq();
2959 /* this cast is needed if >= 128 */3086 /* this cast is needed if >= 128 */
@@ -2962,11 +3089,13 @@ static inline void next_nomacro1(void) · 2 unmodified lines
2962 tokc.i = b;3089 tokc.i = b;
2963 if (ch != '\'')3090 if (ch != '\'')
2964 error("unterminated character constant");3091 error("unterminated character constant");
2965 inp();3092 p = file->buf_ptr;
3093 p++;
2966 break;3094 break;
2967 case '\"':3095 case '\"':
2968 tok = TOK_STR;3096 tok = TOK_STR;
2969 str_const:3097 str_const:
3098 file->buf_ptr = p;
2970 inp();3099 inp();
2971 cstr_reset(&tokcstr);3100 cstr_reset(&tokcstr);
2972 while (ch != '\"') {3101 while (ch != '\"') {
@@ -2983,18 +3112,19 @@ static inline void next_nomacro1(void) · 10 unmodified lines
2983 else3112 else
2984 cstr_wccat(&tokcstr, '\0');3113 cstr_wccat(&tokcstr, '\0');
2985 tokc.cstr = &tokcstr;3114 tokc.cstr = &tokcstr;
2986 inp();3115 p = file->buf_ptr;
3116 p++;
2987 break;3117 break;
2988 3118
2989 case '<':3119 case '<':
2990 cinp();3120 PEEKC(c, p);
2991 if (ch == '=') {3121 if (c == '=') {
2992 cinp();3122 p++;
2993 tok = TOK_LE;3123 tok = TOK_LE;
2994 } else if (ch == '<') {3124 } else if (c == '<') {
2995 cinp();3125 PEEKC(c, p);
2996 if (ch == '=') {3126 if (c == '=') {
2997 cinp();3127 p++;
2998 tok = TOK_A_SHL;3128 tok = TOK_A_SHL;
2999 } else {3129 } else {
3000 tok = TOK_SHL;3130 tok = TOK_SHL;
@@ -3005,14 +3135,14 @@ static inline void next_nomacro1(void) · 4 unmodified lines
3005 break;3135 break;
3006 3136
3007 case '>':3137 case '>':
3008 cinp();3138 PEEKC(c, p);
3009 if (ch == '=') {3139 if (c == '=') {
3010 cinp();3140 p++;
3011 tok = TOK_GE;3141 tok = TOK_GE;
3012 } else if (ch == '>') {3142 } else if (c == '>') {
3013 cinp();3143 PEEKC(c, p);
3014 if (ch == '=') {3144 if (c == '=') {
3015 cinp();3145 p++;
3016 tok = TOK_A_SAR;3146 tok = TOK_A_SAR;
3017 } else {3147 } else {
3018 tok = TOK_SAR;3148 tok = TOK_SAR;
@@ -3022,113 +3152,82 @@ static inline void next_nomacro1(void) · 3 unmodified lines
3022 }3152 }
3023 break;3153 break;
3024 3154
3025 case '!':
3026 tok = ch;
3027 cinp();
3028 if (ch == '=') {
3029 cinp();
3030 tok = TOK_NE;
3031 }
3032 break;
3033
3034 case '=':
3035 tok = ch;
3036 cinp();
3037 if (ch == '=') {
3038 cinp();
3039 tok = TOK_EQ;
3040 }
3041 break;
3042
3043 case '&':3155 case '&':
3044 tok = ch;3156 PEEKC(c, p);
3045 cinp();3157 if (c == '&') {
3046 if (ch == '&') {3158 p++;
3047 cinp();
3048 tok = TOK_LAND;3159 tok = TOK_LAND;
3049 } else if (ch == '=') {3160 } else if (c == '=') {
3050 cinp();3161 p++;
3051 tok = TOK_A_AND;3162 tok = TOK_A_AND;
3163 } else {
3164 tok = '&';
3052 }3165 }
3053 break;3166 break;
3054 3167
3055 case '|':3168 case '|':
3056 tok = ch;3169 PEEKC(c, p);
3057 cinp();3170 if (c == '|') {
3058 if (ch == '|') {3171 p++;
3059 cinp();
3060 tok = TOK_LOR;3172 tok = TOK_LOR;
3061 } else if (ch == '=') {3173 } else if (c == '=') {
3062 cinp();3174 p++;
3063 tok = TOK_A_OR;3175 tok = TOK_A_OR;
3176 } else {
3177 tok = '|';
3064 }3178 }
3065 break;3179 break;
3066 3180
3067 case '+':3181 case '+':
3068 tok = ch;3182 PEEKC(c, p);
3069 cinp();3183 if (c == '+') {
3070 if (ch == '+') {3184 p++;
3071 cinp();
3072 tok = TOK_INC;3185 tok = TOK_INC;
3073 } else if (ch == '=') {3186 } else if (c == '=') {
3074 cinp();3187 p++;
3075 tok = TOK_A_ADD;3188 tok = TOK_A_ADD;
3189 } else {
3190 tok = '+';
3076 }3191 }
3077 break;3192 break;
3078 3193
3079 case '-':3194 case '-':
3080 tok = ch;3195 PEEKC(c, p);
3081 cinp();3196 if (c == '-') {
3082 if (ch == '-') {3197 p++;
3083 cinp();
3084 tok = TOK_DEC;3198 tok = TOK_DEC;
3085 } else if (ch == '=') {3199 } else if (c == '=') {
3086 cinp();3200 p++;
3087 tok = TOK_A_SUB;3201 tok = TOK_A_SUB;
3088 } else if (ch == '>') {3202 } else if (c == '>') {
3089 cinp();3203 p++;
3090 tok = TOK_ARROW;3204 tok = TOK_ARROW;
3205 } else {
3206 tok = '-';
3091 }3207 }
3092 break;3208 break;
3093 3209
3094 case '*':3210 PARSE2('!', '!', '=', TOK_NE)
3095 tok = ch;3211 PARSE2('=', '=', '=', TOK_EQ)
3096 cinp();3212 PARSE2('*', '*', '=', TOK_A_MUL)
3097 if (ch == '=') {3213 PARSE2('%', '%', '=', TOK_A_MOD)
3098 cinp();3214 PARSE2('^', '^', '=', TOK_A_XOR)
3099 tok = TOK_A_MUL;
3100 }
3101 break;
3102
3103 case '%':
3104 tok = ch;
3105 cinp();
3106 if (ch == '=') {
3107 cinp();
3108 tok = TOK_A_MOD;
3109 }
3110 break;
3111 3215
3112 case '^':
3113 tok = ch;
3114 cinp();
3115 if (ch == '=') {
3116 cinp();
3117 tok = TOK_A_XOR;
3118 }
3119 break;
3120
3121 /* comments or operator */3216 /* comments or operator */
3122 case '/':3217 case '/':
3123 minp();3218 PEEKC(c, p);
3124 if (ch == '*') {3219 if (c == '*') {
3220 file->buf_ptr = p;
3125 parse_comment();3221 parse_comment();
3222 p = file->buf_ptr;
3126 goto redo_no_start;3223 goto redo_no_start;
3127 } else if (ch == '/') {3224 } else if (c == '/') {
3225 file->buf_ptr = p;
3128 parse_line_comment();3226 parse_line_comment();
3227 p = file->buf_ptr;
3129 goto redo_no_start;3228 goto redo_no_start;
3130 } else if (ch == '=') {3229 } else if (c == '=') {
3131 cinp();3230 p++;
3132 tok = TOK_A_DIV;3231 tok = TOK_A_DIV;
3133 } else {3232 } else {
3134 tok = '/';3233 tok = '/';
@@ -3147,13 +3246,14 @@ static inline void next_nomacro1(void) · 12 unmodified lines
3147 case ':':3246 case ':':
3148 case '?':3247 case '?':
3149 case '~':3248 case '~':
3150 tok = ch;3249 tok = c;
3151 cinp();3250 p++;
3152 break;3251 break;
3153 default:3252 default:
3154 error("unrecognized character \\x%02x", ch);3253 error("unrecognized character \\x%02x", c);
3155 break;3254 break;
3156 }3255 }
3256 file->buf_ptr = p;
3157 tok_flags = 0;3257 tok_flags = 0;
3158#if defined(PARSE_DEBUG)3258#if defined(PARSE_DEBUG)
3159 printf("token = %s\n", get_tok_str(tok, &tokc));3259 printf("token = %s\n", get_tok_str(tok, &tokc));
@@ -3427,6 +3527,7 @@ static int macro_subst_tok(TokenString *tok_str, · 267 unmodified lines
3427 t = *macro_ptr;3527 t = *macro_ptr;
3428 } else {3528 } else {
3429 /* XXX: incorrect with comments */3529 /* XXX: incorrect with comments */
3530 ch = file->buf_ptr[0];
3430 while (is_space(ch) || ch == '\n')3531 while (is_space(ch) || ch == '\n')
3431 cinp();3532 cinp();
3432 t = ch;3533 t = ch;
tccelf.c+1−1
@@ -1891,7 +1891,7 @@ static int tcc_load_ldscript(TCCState *s1) · 1890 unmodified lines
1891 int t;1891 int t;
1892 1892
1893 ch = file->buf_ptr[0];1893 ch = file->buf_ptr[0];
1894 handle_eob();1894 ch = handle_eob();
1895 for(;;) {1895 for(;;) {
1896 t = ld_next(s1, cmd, sizeof(cmd));1896 t = ld_next(s1, cmd, sizeof(cmd));
1897 if (t == LD_TOK_EOF)1897 if (t == LD_TOK_EOF)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t