History

fix function call and ! operator

bellard committed 24 years ago

Commit 52ca29c1 parent 3c9ab721 file · +34 −31Browse files

Unified · Split

tcc.c+34−31
@@ -128,7 +128,7 @@ int func_vt, func_vc; /* current function return type (used by · 127 unmodified lines
128128 return instruction) */
129129 int tok_ident;
130130 TokenSym **table_ident;
131−TokenSym *hash_ident[521];
131+TokenSym *hash_ident[TOK_HASH_SIZE];
132132 char token_buf[STRING_MAX_SIZE + 1];
133133 char *filename, *funcname;
134134 /* contains global symbols which remain between each translation unit */
@@ -432,7 +432,7 @@ TokenSym *tok_alloc(char *str, int len) · 297 unmodified lines
432432 h = 1;
433433 for(i=0;i<len;i++)
434434 h = ((h << 8) | (str[i] & 0xff)) % TOK_HASH_SIZE;
435−
435+
436436 pts = &hash_ident[h];
437437 while (1) {
438438 ts = *pts;
@@ -451,7 +451,7 @@ TokenSym *tok_alloc(char *str, int len) · 12 unmodified lines
451451 table_ident = ptable;
452452 }
453453 ts = malloc(sizeof(TokenSym) + len);
454− if (!ts)
454+ if (!ts || tok_ident >= SYM_FIRST_ANOM)
455455 error("memory full");
456456 table_ident[i] = ts;
457457 ts->tok = tok_ident++;
@@ -1118,8 +1118,6 @@ void next_nomacro1() · 660 unmodified lines
11181118 *q++ = ch;
11191119 cinp();
11201120 if (q[-1] == 'L') {
1121− /* XXX: not supported entirely (needs different
1122− preprocessor architecture) */
11231121 if (ch == '\'') {
11241122 tok = TOK_LCHAR;
11251123 goto char_const;
@@ -1746,23 +1744,23 @@ void gfunc_param(GFuncContext *c) · 620 unmodified lines
17461744 }
17471745 }
17481746
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)
17511750 {
17521751 int r;
1753− r = ft & VT_VALMASK;
1754− if (r == VT_CONST) {
1752+ if ((vt & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
1753+ /* constant case */
17551754 /* 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);
17581757 oad(0xe8, 0);
17591758 } else {
1760− oad(0xe8, fc - ind - 5);
1759+ oad(0xe8, vc - ind - 5);
17611760 }
1762− } else if (r == VT_LOCAL) {
1763− oad(0x95ff, fc); /* call *xxx(%ebp) */
17641761 } else {
1765− /* not actually used */
1762+ /* otherwise, indirect call */
1763+ r = gv();
17661764 o(0xff); /* call *r */
17671765 o(0xd0 + r);
17681766 }
@@ -1776,7 +1774,7 @@ int gjmp(int t) · 7 unmodified lines
17761774 }
17771775
17781776 /* generate a test. set 'inv' to invert test */
1779−int gtst(inv, t)
1777+int gtst(int inv, int t)
17801778 {
17811779 int v, *p;
17821780 v = vt & VT_VALMASK;
@@ -1813,7 +1811,7 @@ int gtst(inv, t) · 30 unmodified lines
18131811
18141812 /* generate a binary operation 'v = r op fr' instruction and modifies
18151813 (vt,vc) if needed */
1816−void gen_op1(op, r, fr)
1814+void gen_op1(int op, int r, int fr)
18171815 {
18181816 int t;
18191817 if (op == '+') {
@@ -1990,6 +1988,7 @@ void vpush(void) · 170 unmodified lines
19901988 *vstack_ptr++ = vt;
19911989 *vstack_ptr++ = vc;
19921990 /* cannot let cpu flags if other instruction are generated */
1991+ /* XXX: VT_JMP test too ? */
19931992 if ((vt & VT_VALMASK) == VT_CMP)
19941993 gvp(vstack_ptr - 2);
19951994 }
@@ -2207,8 +2206,8 @@ int type_size(int t, int *a) · 211 unmodified lines
22072206 } else if (t & VT_ARRAY) {
22082207 s = sym_find(((unsigned)t >> VT_STRUCT_SHIFT));
22092208 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 ||
22122211 (t & VT_ENUM)) {
22132212 *a = 4;
22142213 return 4;
@@ -2265,7 +2264,8 @@ void vstore(void) · 50 unmodified lines
22652264 gfunc_param(&gf);
22662265
22672266 save_regs();
2268− gfunc_call(&gf, VT_CONST, (int)&memcpy);
2267+ vset(VT_CONST, (int)&memcpy);
2268+ gfunc_call(&gf);
22692269
22702270 /* generate again current type */
22712271 vt = ft;
@@ -2510,13 +2510,14 @@ int post_type(int t) · 238 unmodified lines
25102510 }
25112511 skip(']');
25122512 /* 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));
25142515
25152516 /* we push a anonymous symbol which will contain the array
25162517 element type */
25172518 p = anon_sym++;
25182519 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);
25202521 }
25212522 return t;
25222523 }
@@ -2669,7 +2670,7 @@ void unary(void) · 146 unmodified lines
26692670 } else
26702671 if (t == '!') {
26712672 unary();
2672− if ((vt & (VT_CONST | VT_LVAL)) == VT_CONST)
2673+ if ((vt & (VT_VALMASK | VT_LVAL)) == VT_CONST)
26732674 vc = !vc;
26742675 else if ((vt & VT_VALMASK) == VT_CMP)
26752676 vc = vc ^ 1;
@@ -2780,13 +2781,14 @@ void unary(void) · 104 unmodified lines
27802781 goto error_func;
27812782 } else {
27822783 error_func:
2783− expect("function type");
2784+ expect("function pointer");
27842785 }
2786+ } else {
2787+ vt &= ~VT_LVAL; /* no lvalue */
27852788 }
2789+
27862790 /* get return type */
27872791 s = sym_find((unsigned)vt >> VT_STRUCT_SHIFT);
2788−
2789− vt &= ~VT_LVAL; /* no lvalue */
27902792 vpush(); /* push function address */
27912793 save_regs(); /* save used temporary registers */
27922794 gfunc_start(&gf);
@@ -2865,8 +2867,8 @@ void unary(void) · 72 unmodified lines
28652867 }
28662868 #endif
28672869 skip(')');
2868− vpop(&ft, &fc);
2869− gfunc_call(&gf, ft, fc);
2870+ vpop(&vt, &vc);
2871+ gfunc_call(&gf);
28702872 /* return value */
28712873 vt = rett;
28722874 vc = retc;
@@ -2994,7 +2996,7 @@ void sum(l) · 121 unmodified lines
29942996 }
29952997
29962998 /* only used if non constant */
2997−void eand()
2999+void eand(void)
29983000 {
29993001 int t;
30003002
@@ -3014,7 +3016,7 @@ void eand() · 13 unmodified lines
30143016 }
30153017 }
30163018
3017−void eor()
3019+void eor(void)
30183020 {
30193021 int t;
30203022
@@ -3450,7 +3452,8 @@ void init_putz(int t, int c, int size) · 429 unmodified lines
34503452 gfunc_param(&gf);
34513453 vset(VT_LOCAL, c);
34523454 gfunc_param(&gf);
3453− gfunc_call(&gf, VT_CONST, (int)&memset);
3455+ vset(VT_CONST, (int)&memset);
3456+ gfunc_call(&gf);
34543457 }
34553458 }
34563459

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