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