History

fixed local extern handling - fixed '!' with symbols

bellard committed 24 years ago

Commit 46803f01 parent 41391fb1 file · +43 −30Browse files

Unified · Split

tcc.c+43−30
@@ -592,9 +592,9 @@ void vset(int t, int r, int v); · 591 unmodified lines
592592 void type_to_str(char *buf, int buf_size,
593593 int t, const char *varstr);
594594 char *get_tok_str(int v, CValue *cv);
595−Sym *external_sym(int v, int u, int r);
596595 static Sym *get_sym_ref(int t, Section *sec,
597596 unsigned long offset, unsigned long size);
597+static Sym *external_global_sym(int v, int u, int r);
598598
599599 /* section generation */
600600 static void section_realloc(Section *sec, unsigned long new_size);
@@ -2891,7 +2891,7 @@ static Sym *get_sym_ref(int t, Section *sec, · 2290 unmodified lines
28912891 }
28922892
28932893 /* push a reference to a section offset by adding a dummy symbol */
2894−void vpush_ref(int t, Section *sec, unsigned long offset, unsigned long size)
2894+static void vpush_ref(int t, Section *sec, unsigned long offset, unsigned long size)
28952895 {
28962896 CValue cval;
28972897
@@ -2899,13 +2899,41 @@ void vpush_ref(int t, Section *sec, unsigned long offset, unsigned long size) · 1 unmodified line
28992899 vsetc(t, VT_CONST | VT_SYM, &cval);
29002900 }
29012901
2902+/* define a new external reference to a symbol 'v' of type 'u' */
2903+static Sym *external_global_sym(int v, int u, int r)
2904+{
2905+ Sym *s;
2906+
2907+ s = sym_find(v);
2908+ if (!s) {
2909+ /* push forward reference */
2910+ s = sym_push1(&global_stack,
2911+ v, u | VT_EXTERN, 0);
2912+ s->r = r | VT_CONST | VT_SYM;
2913+ }
2914+ return s;
2915+}
2916+
2917+/* define a new external reference to a symbol 'v' of type 'u' */
2918+static Sym *external_sym(int v, int u, int r)
2919+{
2920+ Sym *s;
2921+
2922+ s = sym_find(v);
2923+ if (!s) {
2924+ /* push forward reference */
2925+ s = sym_push(v, u | VT_EXTERN, r | VT_CONST | VT_SYM, 0);
2926+ }
2927+ return s;
2928+}
2929+
29022930 /* push a reference to global symbol v */
2903−void vpush_sym(int t, int v)
2931+static void vpush_global_sym(int t, int v)
29042932 {
29052933 Sym *sym;
29062934 CValue cval;
29072935
2908− sym = external_sym(v, t, 0);
2936+ sym = external_global_sym(v, t, 0);
29092937 cval.sym = sym;
29102938 vsetc(t, VT_CONST | VT_SYM, &cval);
29112939 }
@@ -3363,7 +3391,7 @@ void gen_opl(int op) · 451 unmodified lines
33633391 gfunc_start(&gf, FUNC_CDECL);
33643392 gfunc_param(&gf);
33653393 gfunc_param(&gf);
3366− vpush_sym(func_old_type, func);
3394+ vpush_global_sym(func_old_type, func);
33673395 gfunc_call(&gf);
33683396 vpushi(0);
33693397 vtop->r = REG_IRET;
@@ -3883,11 +3911,11 @@ void gen_cvt_itof1(int t) · 513 unmodified lines
38833911 gfunc_start(&gf, FUNC_CDECL);
38843912 gfunc_param(&gf);
38853913 if (t == VT_FLOAT)
3886− vpush_sym(func_old_type, TOK___ulltof);
3914+ vpush_global_sym(func_old_type, TOK___ulltof);
38873915 else if (t == VT_DOUBLE)
3888− vpush_sym(func_old_type, TOK___ulltod);
3916+ vpush_global_sym(func_old_type, TOK___ulltod);
38893917 else
3890− vpush_sym(func_old_type, TOK___ulltold);
3918+ vpush_global_sym(func_old_type, TOK___ulltold);
38913919 gfunc_call(&gf);
38923920 vpushi(0);
38933921 vtop->r = REG_FRET;
@@ -3908,11 +3936,11 @@ void gen_cvt_ftoi1(int t) · 14 unmodified lines
39083936 st = vtop->t & VT_BTYPE;
39093937 gfunc_param(&gf);
39103938 if (st == VT_FLOAT)
3911− vpush_sym(func_old_type, TOK___fixunssfdi);
3939+ vpush_global_sym(func_old_type, TOK___fixunssfdi);
39123940 else if (st == VT_DOUBLE)
3913− vpush_sym(func_old_type, TOK___fixunsdfdi);
3941+ vpush_global_sym(func_old_type, TOK___fixunsdfdi);
39143942 else
3915− vpush_sym(func_old_type, TOK___fixunsxfdi);
3943+ vpush_global_sym(func_old_type, TOK___fixunsxfdi);
39163944 gfunc_call(&gf);
39173945 vpushi(0);
39183946 vtop->r = REG_IRET;
@@ -4371,7 +4399,7 @@ void vstore(void) · 452 unmodified lines
43714399 gfunc_param(&gf);
43724400
43734401 save_regs(0);
4374− vpush_sym(func_old_type, TOK_memcpy);
4402+ vpush_global_sym(func_old_type, TOK_memcpy);
43754403 gfunc_call(&gf);
43764404 /* leave source on stack */
43774405 } else if (ft & VT_BITFIELD) {
@@ -4950,21 +4978,6 @@ int type_decl(AttributeDef *ad, int *v, int t, int td) · 572 unmodified lines
49504978 return u;
49514979 }
49524980
4953−/* define a new external reference to a symbol 'v' of type 'u' */
4954−Sym *external_sym(int v, int u, int r)
4955−{
4956− Sym *s;
4957−
4958− s = sym_find(v);
4959− if (!s) {
4960− /* push forward reference */
4961− s = sym_push1(&global_stack,
4962− v, u | VT_EXTERN, 0);
4963− s->r = r | VT_CONST | VT_SYM;
4964− }
4965− return s;
4966−}
4967−
49684981 /* compute the lvalue VT_LVAL_xxx needed to match type t. */
49694982 static int lvalue_type(int t)
49704983 {
@@ -5115,7 +5128,7 @@ void unary(void) · 144 unmodified lines
51155128 } else
51165129 if (t == '!') {
51175130 unary();
5118− if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
5131+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)
51195132 vtop->c.i = !vtop->c.i;
51205133 else if ((vtop->r & VT_VALMASK) == VT_CMP)
51215134 vtop->c.i = vtop->c.i ^ 1;
@@ -5172,7 +5185,7 @@ void unary(void) · 50 unmodified lines
51725185 error("'%s' undeclared", get_tok_str(t, NULL));
51735186 /* for simple function calls, we tolerate undeclared
51745187 external reference to int() function */
5175− s = external_sym(t, func_old_type, 0);
5188+ s = external_global_sym(t, func_old_type, 0);
51765189 }
51775190 vset(s->t, s->r, s->c);
51785191 /* if forward reference, we must point to s */
@@ -5954,7 +5967,7 @@ static void init_putz(int t, Section *sec, unsigned long c, int size) · 775 unmodified lines
59545967 gfunc_param(&gf);
59555968 vset(VT_INT, VT_LOCAL, c);
59565969 gfunc_param(&gf);
5957− vpush_sym(func_old_type, TOK_memset);
5970+ vpush_global_sym(func_old_type, TOK_memset);
59585971 gfunc_call(&gf);
59595972 }
59605973 }

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