Unified · Split
| @@ -128,7 +128,7 @@ int func_vt, func_vc; /* current function return type (used by · 127 unmodified lines | ||
| 128 | 128 | return instruction) */ |
| 129 | 129 | int tok_ident; |
| 130 | 130 | TokenSym **table_ident; |
| 131 | −TokenSym *hash_ident[521]; | |
| 131 | +TokenSym *hash_ident[TOK_HASH_SIZE]; | |
| 132 | 132 | char token_buf[STRING_MAX_SIZE + 1]; |
| 133 | 133 | char *filename, *funcname; |
| 134 | 134 | /* contains global symbols which remain between each translation unit */ |
| @@ -432,7 +432,7 @@ TokenSym *tok_alloc(char *str, int len) · 297 unmodified lines | ||
| 432 | 432 | h = 1; |
| 433 | 433 | for(i=0;i<len;i++) |
| 434 | 434 | h = ((h << 8) | (str[i] & 0xff)) % TOK_HASH_SIZE; |
| 435 | − | |
| 435 | + | |
| 436 | 436 | pts = &hash_ident[h]; |
| 437 | 437 | while (1) { |
| 438 | 438 | ts = *pts; |
| @@ -451,7 +451,7 @@ TokenSym *tok_alloc(char *str, int len) · 12 unmodified lines | ||
| 451 | 451 | table_ident = ptable; |
| 452 | 452 | } |
| 453 | 453 | ts = malloc(sizeof(TokenSym) + len); |
| 454 | − if (!ts) | |
| 454 | + if (!ts || tok_ident >= SYM_FIRST_ANOM) | |
| 455 | 455 | error("memory full"); |
| 456 | 456 | table_ident[i] = ts; |
| 457 | 457 | ts->tok = tok_ident++; |
| @@ -1118,8 +1118,6 @@ void next_nomacro1() · 660 unmodified lines | ||
| 1118 | 1118 | *q++ = ch; |
| 1119 | 1119 | cinp(); |
| 1120 | 1120 | if (q[-1] == 'L') { |
| 1121 | − /* XXX: not supported entirely (needs different | |
| 1122 | − preprocessor architecture) */ | |
| 1123 | 1121 | if (ch == '\'') { |
| 1124 | 1122 | tok = TOK_LCHAR; |
| 1125 | 1123 | goto char_const; |
| @@ -1746,23 +1744,23 @@ void gfunc_param(GFuncContext *c) · 620 unmodified lines | ||
| 1746 | 1744 | } |
| 1747 | 1745 | } |
| 1748 | 1746 | |
| 1749 | −/* generate function call with address in (ft, fc) and free function */ | |
| 1750 | −void gfunc_call(GFuncContext *c, int ft, int fc) | |
| 1747 | +/* generate function call with address in (vt, vc) and free function | |
| 1748 | + context */ | |
| 1749 | +void gfunc_call(GFuncContext *c) | |
| 1751 | 1750 | { |
| 1752 | 1751 | int r; |
| 1753 | − r = ft & VT_VALMASK; | |
| 1754 | − if (r == VT_CONST) { | |
| 1752 | + if ((vt & (VT_VALMASK | VT_LVAL)) == VT_CONST) { | |
| 1753 | + /* constant case */ | |
| 1755 | 1754 | /* forward reference */ |
| 1756 | − if (ft & VT_FORWARD) { | |
| 1757 | − greloc((Sym *)fc, ind + 1, RELOC_REL32); | |
| 1755 | + if (vt & VT_FORWARD) { | |
| 1756 | + greloc((Sym *)vc, ind + 1, RELOC_REL32); | |
| 1758 | 1757 | oad(0xe8, 0); |
| 1759 | 1758 | } else { |
| 1760 | − oad(0xe8, fc - ind - 5); | |
| 1759 | + oad(0xe8, vc - ind - 5); | |
| 1761 | 1760 | } |
| 1762 | − } else if (r == VT_LOCAL) { | |
| 1763 | − oad(0x95ff, fc); /* call *xxx(%ebp) */ | |
| 1764 | 1761 | } else { |
| 1765 | − /* not actually used */ | |
| 1762 | + /* otherwise, indirect call */ | |
| 1763 | + r = gv(); | |
| 1766 | 1764 | o(0xff); /* call *r */ |
| 1767 | 1765 | o(0xd0 + r); |
| 1768 | 1766 | } |
| @@ -1776,7 +1774,7 @@ int gjmp(int t) · 7 unmodified lines | ||
| 1776 | 1774 | } |
| 1777 | 1775 | |
| 1778 | 1776 | /* generate a test. set 'inv' to invert test */ |
| 1779 | −int gtst(inv, t) | |
| 1777 | +int gtst(int inv, int t) | |
| 1780 | 1778 | { |
| 1781 | 1779 | int v, *p; |
| 1782 | 1780 | v = vt & VT_VALMASK; |
| @@ -1813,7 +1811,7 @@ int gtst(inv, t) · 30 unmodified lines | ||
| 1813 | 1811 | |
| 1814 | 1812 | /* generate a binary operation 'v = r op fr' instruction and modifies |
| 1815 | 1813 | (vt,vc) if needed */ |
| 1816 | −void gen_op1(op, r, fr) | |
| 1814 | +void gen_op1(int op, int r, int fr) | |
| 1817 | 1815 | { |
| 1818 | 1816 | int t; |
| 1819 | 1817 | if (op == '+') { |
| @@ -1990,6 +1988,7 @@ void vpush(void) · 170 unmodified lines | ||
| 1990 | 1988 | *vstack_ptr++ = vt; |
| 1991 | 1989 | *vstack_ptr++ = vc; |
| 1992 | 1990 | /* cannot let cpu flags if other instruction are generated */ |
| 1991 | + /* XXX: VT_JMP test too ? */ | |
| 1993 | 1992 | if ((vt & VT_VALMASK) == VT_CMP) |
| 1994 | 1993 | gvp(vstack_ptr - 2); |
| 1995 | 1994 | } |
| @@ -2207,8 +2206,8 @@ int type_size(int t, int *a) · 211 unmodified lines | ||
| 2207 | 2206 | } else if (t & VT_ARRAY) { |
| 2208 | 2207 | s = sym_find(((unsigned)t >> VT_STRUCT_SHIFT)); |
| 2209 | 2208 | return type_size(s->t, a) * s->c; |
| 2210 | − } else if ((t & VT_PTR) | | |
| 2211 | − (t & VT_TYPE) == 0 | | |
| 2209 | + } else if ((t & VT_PTR) || | |
| 2210 | + (t & VT_TYPE & ~VT_UNSIGNED) == VT_INT || | |
| 2212 | 2211 | (t & VT_ENUM)) { |
| 2213 | 2212 | *a = 4; |
| 2214 | 2213 | return 4; |
| @@ -2265,7 +2264,8 @@ void vstore(void) · 50 unmodified lines | ||
| 2265 | 2264 | gfunc_param(&gf); |
| 2266 | 2265 | |
| 2267 | 2266 | save_regs(); |
| 2268 | − gfunc_call(&gf, VT_CONST, (int)&memcpy); | |
| 2267 | + vset(VT_CONST, (int)&memcpy); | |
| 2268 | + gfunc_call(&gf); | |
| 2269 | 2269 | |
| 2270 | 2270 | /* generate again current type */ |
| 2271 | 2271 | vt = ft; |
| @@ -2510,13 +2510,14 @@ int post_type(int t) · 238 unmodified lines | ||
| 2510 | 2510 | } |
| 2511 | 2511 | skip(']'); |
| 2512 | 2512 | /* parse next post type */ |
| 2513 | − t = post_type(t); | |
| 2513 | + t1 = t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN); | |
| 2514 | + t = post_type(t & ~(VT_TYPEDEF | VT_STATIC | VT_EXTERN)); | |
| 2514 | 2515 | |
| 2515 | 2516 | /* we push a anonymous symbol which will contain the array |
| 2516 | 2517 | element type */ |
| 2517 | 2518 | p = anon_sym++; |
| 2518 | 2519 | sym_push(p, t, n); |
| 2519 | − t = VT_ARRAY | VT_PTR | (p << VT_STRUCT_SHIFT); | |
| 2520 | + t = t1 | VT_ARRAY | VT_PTR | (p << VT_STRUCT_SHIFT); | |
| 2520 | 2521 | } |
| 2521 | 2522 | return t; |
| 2522 | 2523 | } |
| @@ -2669,7 +2670,7 @@ void unary(void) · 146 unmodified lines | ||
| 2669 | 2670 | } else |
| 2670 | 2671 | if (t == '!') { |
| 2671 | 2672 | unary(); |
| 2672 | − if ((vt & (VT_CONST | VT_LVAL)) == VT_CONST) | |
| 2673 | + if ((vt & (VT_VALMASK | VT_LVAL)) == VT_CONST) | |
| 2673 | 2674 | vc = !vc; |
| 2674 | 2675 | else if ((vt & VT_VALMASK) == VT_CMP) |
| 2675 | 2676 | vc = vc ^ 1; |
| @@ -2780,13 +2781,14 @@ void unary(void) · 104 unmodified lines | ||
| 2780 | 2781 | goto error_func; |
| 2781 | 2782 | } else { |
| 2782 | 2783 | error_func: |
| 2783 | − expect("function type"); | |
| 2784 | + expect("function pointer"); | |
| 2784 | 2785 | } |
| 2786 | + } else { | |
| 2787 | + vt &= ~VT_LVAL; /* no lvalue */ | |
| 2785 | 2788 | } |
| 2789 | + | |
| 2786 | 2790 | /* get return type */ |
| 2787 | 2791 | s = sym_find((unsigned)vt >> VT_STRUCT_SHIFT); |
| 2788 | − | |
| 2789 | − vt &= ~VT_LVAL; /* no lvalue */ | |
| 2790 | 2792 | vpush(); /* push function address */ |
| 2791 | 2793 | save_regs(); /* save used temporary registers */ |
| 2792 | 2794 | gfunc_start(&gf); |
| @@ -2865,8 +2867,8 @@ void unary(void) · 72 unmodified lines | ||
| 2865 | 2867 | } |
| 2866 | 2868 | #endif |
| 2867 | 2869 | skip(')'); |
| 2868 | − vpop(&ft, &fc); | |
| 2869 | − gfunc_call(&gf, ft, fc); | |
| 2870 | + vpop(&vt, &vc); | |
| 2871 | + gfunc_call(&gf); | |
| 2870 | 2872 | /* return value */ |
| 2871 | 2873 | vt = rett; |
| 2872 | 2874 | vc = retc; |
| @@ -2994,7 +2996,7 @@ void sum(l) · 121 unmodified lines | ||
| 2994 | 2996 | } |
| 2995 | 2997 | |
| 2996 | 2998 | /* only used if non constant */ |
| 2997 | −void eand() | |
| 2999 | +void eand(void) | |
| 2998 | 3000 | { |
| 2999 | 3001 | int t; |
| 3000 | 3002 | |
| @@ -3014,7 +3016,7 @@ void eand() · 13 unmodified lines | ||
| 3014 | 3016 | } |
| 3015 | 3017 | } |
| 3016 | 3018 | |
| 3017 | −void eor() | |
| 3019 | +void eor(void) | |
| 3018 | 3020 | { |
| 3019 | 3021 | int t; |
| 3020 | 3022 | |
| @@ -3450,7 +3452,8 @@ void init_putz(int t, int c, int size) · 429 unmodified lines | ||
| 3450 | 3452 | gfunc_param(&gf); |
| 3451 | 3453 | vset(VT_LOCAL, c); |
| 3452 | 3454 | gfunc_param(&gf); |
| 3453 | − gfunc_call(&gf, VT_CONST, (int)&memset); | |
| 3455 | + vset(VT_CONST, (int)&memset); | |
| 3456 | + gfunc_call(&gf); | |
| 3454 | 3457 | } |
| 3455 | 3458 | } |
| 3456 | 3459 | |