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
11181118 TokenSym *tok_alloc(const char *str, int len)
11191119 {
11201120 TokenSym *ts, **pts, **ptable;
1121− int h, i;
1121+ int i;
1122+ unsigned int h;
11221123
11231124 h = 1;
11241125 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);
11261128
11271129 pts = &hash_ident[h];
11281130 while (1) {
@@ -1522,7 +1524,12 @@ static int tcc_peekc_slow(BufferedFile *bf) · 393 unmodified lines
15221524 /* only tries to read if really end of buffer */
15231525 if (bf->buf_ptr >= bf->buf_end) {
15241526 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);
15261533 if (len < 0)
15271534 len = 0;
15281535 } else {
@@ -1541,13 +1548,11 @@ static int tcc_peekc_slow(BufferedFile *bf) · 12 unmodified lines
15411548 }
15421549 }
15431550
1544−/* no need to put that inline */
1545−void handle_eob(void)
1551+/* return the current character, handling end of block if necessary
1552+ (but not stray) */
1553+static int handle_eob(void)
15461554 {
1547− /* no need to do anything if not at EOB */
1548− if (file->buf_ptr < file->buf_end)
1549− return;
1550− ch = tcc_peekc_slow(file);
1555+ return tcc_peekc_slow(file);
15511556 }
15521557
15531558 /* 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
15561561 ch = *(++(file->buf_ptr));
15571562 /* end of buffer/file handling */
15581563 if (ch == CH_EOB)
1559− handle_eob();
1564+ ch = handle_eob();
15601565 }
15611566
15621567 /* handle '\[\r]\n' */
@@ -1580,6 +1585,40 @@ static void handle_stray(void) · 17 unmodified lines
15801585 }
15811586 }
15821587
1588+/* skip the stray and handle the \\n case. Output an error if
1589+ incorrect char after the stray */
1590+static 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+
15831622 /* input with '\[\r]\n' handling. Note that this function cannot
15841623 handle other characters after '\', so you cannot call it inside
15851624 strings or comments */
@@ -1606,8 +1645,8 @@ static void parse_comment(void) · 20 unmodified lines
16061645 int c;
16071646
16081647 /* C comments */
1609− minp();
16101648 p = file->buf_ptr;
1649+ p++;
16111650 for(;;) {
16121651 /* fast skip loop */
16131652 for(;;) {
@@ -1628,49 +1667,49 @@ static void parse_comment(void) · 14 unmodified lines
16281667 p++;
16291668 for(;;) {
16301669 c = *p;
1631− if (c == '/') {
1670+ if (c == '*') {
1671+ p++;
1672+ } else if (c == '/') {
16321673 goto end_of_comment;
16331674 } else if (c == '\\') {
1634− if (p >= file->buf_end) {
1635− file->buf_ptr = p;
1636− handle_eob();
1637− p = file->buf_ptr;
1638− if (p >= file->buf_end)
1639− goto eof_found;
1640− continue;
1641− }
1642− p++;
1643− c = *p;
1644− if (c == '\n') {
1645− file->line_num++;
1646− p++;
1647− } else if (c == '\r') {
1648− p++;
1649− c = *p;
1650− if (c != '\n')
1651− break;
1652− file->line_num++;
1653− p++;
1654− } else {
1655− break;
1675+ file->buf_ptr = p;
1676+ c = handle_eob();
1677+ if (c == '\\') {
1678+ /* skip '\\n', but if '\' followed but another
1679+ char, behave asif a stray was parsed */
1680+ ch = file->buf_ptr[0];
1681+ while (ch == '\\') {
1682+ inp();
1683+ if (ch == '\n') {
1684+ file->line_num++;
1685+ inp();
1686+ } else if (ch == '\r') {
1687+ inp();
1688+ if (ch == '\n') {
1689+ file->line_num++;
1690+ inp();
1691+ }
1692+ } else {
1693+ p = file->buf_ptr;
1694+ break;
1695+ }
1696+ }
16561697 }
1657− } else if (c == '*') {
1658− p++;
1698+ p = file->buf_ptr;
16591699 } else {
16601700 break;
16611701 }
16621702 }
1663− } else if (p >= file->buf_end) {
1703+ } else {
1704+ /* stray, eob or eof */
16641705 file->buf_ptr = p;
1665− handle_eob();
1706+ c = handle_eob();
16661707 p = file->buf_ptr;
1667− if (p >= file->buf_end) {
1668− eof_found:
1708+ if (c == CH_EOF) {
16691709 error("unexpected end of file in comment");
1710+ } else if (c == '\\') {
1711+ p++;
16701712 }
1671− } else {
1672− /* stray */
1673− p++;
16741713 }
16751714 }
16761715 end_of_comment:
@@ -1697,63 +1736,98 @@ static inline void skip_spaces(void) · 20 unmodified lines
16971736 #if/#endif */
16981737 void preprocess_skip(void)
16991738 {
1700− int a, start_of_line, sep;
1701−
1739+ int a, start_of_line, sep, c;
1740+ uint8_t *p;
1741+
1742+ p = file->buf_ptr;
17021743 start_of_line = 1;
17031744 a = 0;
17041745 for(;;) {
17051746 redo_no_start:
1706− switch(ch) {
1747+ c = *p;
1748+ switch(c) {
17071749 case ' ':
17081750 case '\t':
17091751 case '\f':
17101752 case '\v':
17111753 case '\r':
1712− inp();
1754+ p++;
17131755 goto redo_no_start;
17141756 case '\n':
17151757 start_of_line = 1;
17161758 file->line_num++;
1717− inp();
1759+ p++;
17181760 goto redo_no_start;
17191761 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;
17211772 goto redo_no_start;
17221773 /* skip strings */
17231774 case '\"':
17241775 case '\'':
1725− sep = ch;
1726− inp();
1727− while (ch != sep) {
1728− /* XXX: better error message */
1729− if (ch == TOK_EOF) {
1730− error("unterminated string");
1731− } else if (ch == '\n') {
1776+ sep = c;
1777+ p++;
1778+ for(;;) {
1779+ c = *p;
1780+ if (c == sep) {
1781+ break;
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') {
17321804 file->line_num++;
1733− } else if (ch == '\\') {
1734− /* ignore next char */
1735− inp();
1736− if (ch == '\n')
1737− file->line_num++;
1805+ p++;
1806+ } else {
1807+ p++;
17381808 }
1739− inp();
17401809 }
1741− minp();
1810+ p++;
17421811 break;
17431812 /* skip comments */
17441813 case '/':
1814+ file->buf_ptr = p;
1815+ ch = *p;
17451816 minp();
17461817 if (ch == '*') {
17471818 parse_comment();
17481819 } else if (ch == '/') {
17491820 parse_line_comment();
17501821 }
1822+ p = file->buf_ptr;
17511823 break;
17521824
17531825 case '#':
1754− minp();
1826+ p++;
17551827 if (start_of_line) {
1828+ file->buf_ptr = p;
17561829 next_nomacro();
1830+ p = file->buf_ptr;
17571831 if (a == 0 &&
17581832 (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF))
17591833 goto the_end;
@@ -1763,16 +1837,14 @@ void preprocess_skip(void) · 3 unmodified lines
17631837 a--;
17641838 }
17651839 break;
1766− case CH_EOF:
1767− expect("#endif");
1768− break;
17691840 default:
1770− inp();
1841+ p++;
17711842 break;
17721843 }
17731844 start_of_line = 0;
17741845 }
17751846 the_end: ;
1847+ file->buf_ptr = p;
17761848 }
17771849
17781850 /* ParseState handling */
@@ -2040,10 +2112,10 @@ void tok_print(int *str) · 261 unmodified lines
20402112 #endif
20412113
20422114 /* parse after #define */
2043−void parse_define(void)
2115+static void parse_define(void)
20442116 {
20452117 Sym *s, *first, **ps;
2046− int v, t, varg, is_vaargs;
2118+ int v, t, varg, is_vaargs, c;
20472119 TokenString str;
20482120
20492121 v = tok;
@@ -2053,7 +2125,10 @@ void parse_define(void) · 3 unmodified lines
20532125 first = NULL;
20542126 t = MACRO_OBJ;
20552127 /* '(' 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 == '(') {
20572132 next_nomacro();
20582133 next_nomacro();
20592134 ps = &first;
@@ -2156,6 +2231,8 @@ static void preprocess(int is_bof) · 96 unmodified lines
21562231 define_undef(s);
21572232 break;
21582233 case TOK_INCLUDE:
2234+ ch = file->buf_ptr[0];
2235+ /* XXX: incorrect if comments : use next_nomacro with a special mode */
21592236 skip_spaces();
21602237 if (ch == '<') {
21612238 c = '>';
@@ -2781,32 +2858,55 @@ void parse_number(const char *p) · 619 unmodified lines
27812858 }
27822859 }
27832860
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+
27842873 /* return next token without macro substitution */
27852874 static inline void next_nomacro1(void)
27862875 {
2787− int b, t;
2788− char *q;
2876+ int b, t, c;
27892877 TokenSym *ts;
2878+ uint8_t *p, *p1;
27902879
2880+ p = file->buf_ptr;
27912881 redo_no_start:
2792− switch(ch) {
2882+ c = *p;
2883+ switch(c) {
27932884 case ' ':
27942885 case '\t':
27952886 case '\f':
27962887 case '\v':
27972888 case '\r':
2798− inp();
2889+ p++;
27992890 goto redo_no_start;
28002891
28012892 case '\\':
28022893 /* first look if it is in fact an end of buffer */
2803− handle_eob();
2804− if (ch != '\\')
2894+ if (p >= file->buf_end) {
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;
28052907 goto redo_no_start;
2806− handle_stray();
2807− goto redo_no_start;
2808−
2809− case CH_EOF:
2908+ }
2909+ parse_eof:
28102910 {
28112911 TCCState *s1 = tcc_state;
28122912
@@ -2837,6 +2937,7 @@ static inline void next_nomacro1(void) · 24 unmodified lines
28372937 s1->include_stack_ptr--;
28382938 file = *s1->include_stack_ptr;
28392939 inp();
2940+ p = file->buf_ptr;
28402941 goto redo_no_start;
28412942 }
28422943 }
@@ -2848,19 +2949,22 @@ static inline void next_nomacro1(void) · 5 unmodified lines
28482949 tok = TOK_LINEFEED;
28492950 } else {
28502951 tok_flags |= TOK_FLAG_BOL;
2851− inp();
2952+ p++;
28522953 goto redo_no_start;
28532954 }
28542955 break;
28552956
28562957 case '#':
2857− minp();
2958+ /* XXX: simplify */
2959+ PEEKC(c, p);
28582960 if (tok_flags & TOK_FLAG_BOL) {
2961+ file->buf_ptr = p;
28592962 preprocess(tok_flags & TOK_FLAG_BOF);
2963+ p = file->buf_ptr;
28602964 goto redo_no_start;
28612965 } else {
2862− if (ch == '#') {
2863− inp();
2966+ if (c == '#') {
2967+ p++;
28642968 tok = TOK_TWOSHARPS;
28652969 } else {
28662970 tok = '#';
@@ -2883,34 +2987,57 @@ static inline void next_nomacro1(void) · 16 unmodified lines
28832987 case 'U': case 'V': case 'W': case 'X':
28842988 case 'Y': case 'Z':
28852989 case '_':
2886− q = token_buf;
2887− *q++ = ch;
2888− cinp();
2889− parse_ident:
2890− while (isid(ch) || isnum(ch)) {
2891− if (q >= token_buf + STRING_MAX_SIZE)
2892− error("ident too long");
2893− *q++ = ch;
2894− cinp();
2990+ parse_ident_fast:
2991+ p1 = p;
2992+ p++;
2993+ for(;;) {
2994+ c = *p;
2995+ if (!isid(c) && !isnum(c))
2996+ break;
2997+ p++;
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);
28953018 }
2896− *q = '\0';
2897− ts = tok_alloc(token_buf, q - token_buf);
28983019 tok = ts->tok;
28993020 break;
29003021 case 'L':
2901− minp();
2902− if (ch == '\'') {
2903− tok = TOK_LCHAR;
2904− goto char_const;
2905− }
2906− if (ch == '\"') {
2907− tok = TOK_LSTR;
2908− goto str_const;
3022+ c = p[1];
3023+ if (c != '\\' && c != '\'' && c != '\"') {
3024+ /* fast case */
3025+ goto parse_ident_fast;
3026+ } else {
3027+ PEEKC(c, p);
3028+ if (c == '\'') {
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+ }
29093039 }
2910− q = token_buf;
2911− *q++ = 'L';
2912− goto parse_ident;
2913−
3040+ break;
29143041 case '0': case '1': case '2': case '3':
29153042 case '4': case '5': case '6': case '7':
29163043 case '8': case '9':
@@ -2920,11 +3047,11 @@ static inline void next_nomacro1(void) · 3 unmodified lines
29203047 prefixed by 'eEpP' */
29213048 parse_num:
29223049 for(;;) {
2923− t = ch;
2924− cstr_ccat(&tokcstr, ch);
2925− cinp();
2926− if (!(isnum(ch) || isid(ch) || ch == '.' ||
2927− ((ch == '+' || ch == '-') &&
3050+ t = c;
3051+ cstr_ccat(&tokcstr, c);
3052+ PEEKC(c, p);
3053+ if (!(isnum(c) || isid(c) || c == '.' ||
3054+ ((c == '+' || c == '-') &&
29283055 (t == 'e' || t == 'E' || t == 'p' || t == 'P'))))
29293056 break;
29303057 }
@@ -2935,17 +3062,16 @@ static inline void next_nomacro1(void) · 4 unmodified lines
29353062 break;
29363063 case '.':
29373064 /* special dot handling because it can also start a number */
2938− cinp();
2939− if (isnum(ch)) {
3065+ PEEKC(c, p);
3066+ if (isnum(c)) {
29403067 cstr_reset(&tokcstr);
29413068 cstr_ccat(&tokcstr, '.');
29423069 goto parse_num;
2943− }
2944− if (ch == '.') {
2945− cinp();
2946− if (ch != '.')
3070+ } else if (c == '.') {
3071+ PEEKC(c, p);
3072+ if (c != '.')
29473073 expect("'.'");
2948− cinp();
3074+ PEEKC(c, p);
29493075 tok = TOK_DOTS;
29503076 } else {
29513077 tok = '.';
@@ -2954,6 +3080,7 @@ static inline void next_nomacro1(void) · 2 unmodified lines
29543080 case '\'':
29553081 tok = TOK_CCHAR;
29563082 char_const:
3083+ file->buf_ptr = p;
29573084 inp();
29583085 b = getq();
29593086 /* this cast is needed if >= 128 */
@@ -2962,11 +3089,13 @@ static inline void next_nomacro1(void) · 2 unmodified lines
29623089 tokc.i = b;
29633090 if (ch != '\'')
29643091 error("unterminated character constant");
2965− inp();
3092+ p = file->buf_ptr;
3093+ p++;
29663094 break;
29673095 case '\"':
29683096 tok = TOK_STR;
29693097 str_const:
3098+ file->buf_ptr = p;
29703099 inp();
29713100 cstr_reset(&tokcstr);
29723101 while (ch != '\"') {
@@ -2983,18 +3112,19 @@ static inline void next_nomacro1(void) · 10 unmodified lines
29833112 else
29843113 cstr_wccat(&tokcstr, '\0');
29853114 tokc.cstr = &tokcstr;
2986− inp();
3115+ p = file->buf_ptr;
3116+ p++;
29873117 break;
29883118
29893119 case '<':
2990− cinp();
2991− if (ch == '=') {
2992− cinp();
3120+ PEEKC(c, p);
3121+ if (c == '=') {
3122+ p++;
29933123 tok = TOK_LE;
2994− } else if (ch == '<') {
2995− cinp();
2996− if (ch == '=') {
2997− cinp();
3124+ } else if (c == '<') {
3125+ PEEKC(c, p);
3126+ if (c == '=') {
3127+ p++;
29983128 tok = TOK_A_SHL;
29993129 } else {
30003130 tok = TOK_SHL;
@@ -3005,14 +3135,14 @@ static inline void next_nomacro1(void) · 4 unmodified lines
30053135 break;
30063136
30073137 case '>':
3008− cinp();
3009− if (ch == '=') {
3010− cinp();
3138+ PEEKC(c, p);
3139+ if (c == '=') {
3140+ p++;
30113141 tok = TOK_GE;
3012− } else if (ch == '>') {
3013− cinp();
3014− if (ch == '=') {
3015− cinp();
3142+ } else if (c == '>') {
3143+ PEEKC(c, p);
3144+ if (c == '=') {
3145+ p++;
30163146 tok = TOK_A_SAR;
30173147 } else {
30183148 tok = TOK_SAR;
@@ -3022,113 +3152,82 @@ static inline void next_nomacro1(void) · 3 unmodified lines
30223152 }
30233153 break;
30243154
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−
30433155 case '&':
3044− tok = ch;
3045− cinp();
3046− if (ch == '&') {
3047− cinp();
3156+ PEEKC(c, p);
3157+ if (c == '&') {
3158+ p++;
30483159 tok = TOK_LAND;
3049− } else if (ch == '=') {
3050− cinp();
3160+ } else if (c == '=') {
3161+ p++;
30513162 tok = TOK_A_AND;
3163+ } else {
3164+ tok = '&';
30523165 }
30533166 break;
30543167
30553168 case '|':
3056− tok = ch;
3057− cinp();
3058− if (ch == '|') {
3059− cinp();
3169+ PEEKC(c, p);
3170+ if (c == '|') {
3171+ p++;
30603172 tok = TOK_LOR;
3061− } else if (ch == '=') {
3062− cinp();
3173+ } else if (c == '=') {
3174+ p++;
30633175 tok = TOK_A_OR;
3176+ } else {
3177+ tok = '|';
30643178 }
30653179 break;
30663180
30673181 case '+':
3068− tok = ch;
3069− cinp();
3070− if (ch == '+') {
3071− cinp();
3182+ PEEKC(c, p);
3183+ if (c == '+') {
3184+ p++;
30723185 tok = TOK_INC;
3073− } else if (ch == '=') {
3074− cinp();
3186+ } else if (c == '=') {
3187+ p++;
30753188 tok = TOK_A_ADD;
3189+ } else {
3190+ tok = '+';
30763191 }
30773192 break;
30783193
30793194 case '-':
3080− tok = ch;
3081− cinp();
3082− if (ch == '-') {
3083− cinp();
3195+ PEEKC(c, p);
3196+ if (c == '-') {
3197+ p++;
30843198 tok = TOK_DEC;
3085− } else if (ch == '=') {
3086− cinp();
3199+ } else if (c == '=') {
3200+ p++;
30873201 tok = TOK_A_SUB;
3088− } else if (ch == '>') {
3089− cinp();
3202+ } else if (c == '>') {
3203+ p++;
30903204 tok = TOK_ARROW;
3205+ } else {
3206+ tok = '-';
30913207 }
30923208 break;
30933209
3094− case '*':
3095− tok = ch;
3096− cinp();
3097− if (ch == '=') {
3098− cinp();
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;
3210+ PARSE2('!', '!', '=', TOK_NE)
3211+ PARSE2('=', '=', '=', TOK_EQ)
3212+ PARSE2('*', '*', '=', TOK_A_MUL)
3213+ PARSE2('%', '%', '=', TOK_A_MOD)
3214+ PARSE2('^', '^', '=', TOK_A_XOR)
31113215
3112− case '^':
3113− tok = ch;
3114− cinp();
3115− if (ch == '=') {
3116− cinp();
3117− tok = TOK_A_XOR;
3118− }
3119− break;
3120−
31213216 /* comments or operator */
31223217 case '/':
3123− minp();
3124− if (ch == '*') {
3218+ PEEKC(c, p);
3219+ if (c == '*') {
3220+ file->buf_ptr = p;
31253221 parse_comment();
3222+ p = file->buf_ptr;
31263223 goto redo_no_start;
3127− } else if (ch == '/') {
3224+ } else if (c == '/') {
3225+ file->buf_ptr = p;
31283226 parse_line_comment();
3227+ p = file->buf_ptr;
31293228 goto redo_no_start;
3130− } else if (ch == '=') {
3131− cinp();
3229+ } else if (c == '=') {
3230+ p++;
31323231 tok = TOK_A_DIV;
31333232 } else {
31343233 tok = '/';
@@ -3147,13 +3246,14 @@ static inline void next_nomacro1(void) · 12 unmodified lines
31473246 case ':':
31483247 case '?':
31493248 case '~':
3150− tok = ch;
3151− cinp();
3249+ tok = c;
3250+ p++;
31523251 break;
31533252 default:
3154− error("unrecognized character \\x%02x", ch);
3253+ error("unrecognized character \\x%02x", c);
31553254 break;
31563255 }
3256+ file->buf_ptr = p;
31573257 tok_flags = 0;
31583258 #if defined(PARSE_DEBUG)
31593259 printf("token = %s\n", get_tok_str(tok, &tokc));
@@ -3427,6 +3527,7 @@ static int macro_subst_tok(TokenString *tok_str, · 267 unmodified lines
34273527 t = *macro_ptr;
34283528 } else {
34293529 /* XXX: incorrect with comments */
3530+ ch = file->buf_ptr[0];
34303531 while (is_space(ch) || ch == '\n')
34313532 cinp();
34323533 t = ch;
tccelf.c+1−1
@@ -1891,7 +1891,7 @@ static int tcc_load_ldscript(TCCState *s1) · 1890 unmodified lines
18911891 int t;
18921892
18931893 ch = file->buf_ptr[0];
1894− handle_eob();
1894+ ch = handle_eob();
18951895 for(;;) {
18961896 t = ld_next(s1, cmd, sizeof(cmd));
18971897 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