Unified · Split
| @@ -592,9 +592,9 @@ void vset(int t, int r, int v); · 591 unmodified lines | ||
| 592 | 592 | void type_to_str(char *buf, int buf_size, |
| 593 | 593 | int t, const char *varstr); |
| 594 | 594 | char *get_tok_str(int v, CValue *cv); |
| 595 | −Sym *external_sym(int v, int u, int r); | |
| 596 | 595 | static Sym *get_sym_ref(int t, Section *sec, |
| 597 | 596 | unsigned long offset, unsigned long size); |
| 597 | +static Sym *external_global_sym(int v, int u, int r); | |
| 598 | 598 | |
| 599 | 599 | /* section generation */ |
| 600 | 600 | 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 | ||
| 2891 | 2891 | } |
| 2892 | 2892 | |
| 2893 | 2893 | /* 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) | |
| 2895 | 2895 | { |
| 2896 | 2896 | CValue cval; |
| 2897 | 2897 | |
| @@ -2899,13 +2899,41 @@ void vpush_ref(int t, Section *sec, unsigned long offset, unsigned long size) · 1 unmodified line | ||
| 2899 | 2899 | vsetc(t, VT_CONST | VT_SYM, &cval); |
| 2900 | 2900 | } |
| 2901 | 2901 | |
| 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 | + | |
| 2902 | 2930 | /* 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) | |
| 2904 | 2932 | { |
| 2905 | 2933 | Sym *sym; |
| 2906 | 2934 | CValue cval; |
| 2907 | 2935 | |
| 2908 | − sym = external_sym(v, t, 0); | |
| 2936 | + sym = external_global_sym(v, t, 0); | |
| 2909 | 2937 | cval.sym = sym; |
| 2910 | 2938 | vsetc(t, VT_CONST | VT_SYM, &cval); |
| 2911 | 2939 | } |
| @@ -3363,7 +3391,7 @@ void gen_opl(int op) · 451 unmodified lines | ||
| 3363 | 3391 | gfunc_start(&gf, FUNC_CDECL); |
| 3364 | 3392 | gfunc_param(&gf); |
| 3365 | 3393 | gfunc_param(&gf); |
| 3366 | − vpush_sym(func_old_type, func); | |
| 3394 | + vpush_global_sym(func_old_type, func); | |
| 3367 | 3395 | gfunc_call(&gf); |
| 3368 | 3396 | vpushi(0); |
| 3369 | 3397 | vtop->r = REG_IRET; |
| @@ -3883,11 +3911,11 @@ void gen_cvt_itof1(int t) · 513 unmodified lines | ||
| 3883 | 3911 | gfunc_start(&gf, FUNC_CDECL); |
| 3884 | 3912 | gfunc_param(&gf); |
| 3885 | 3913 | if (t == VT_FLOAT) |
| 3886 | − vpush_sym(func_old_type, TOK___ulltof); | |
| 3914 | + vpush_global_sym(func_old_type, TOK___ulltof); | |
| 3887 | 3915 | else if (t == VT_DOUBLE) |
| 3888 | − vpush_sym(func_old_type, TOK___ulltod); | |
| 3916 | + vpush_global_sym(func_old_type, TOK___ulltod); | |
| 3889 | 3917 | else |
| 3890 | − vpush_sym(func_old_type, TOK___ulltold); | |
| 3918 | + vpush_global_sym(func_old_type, TOK___ulltold); | |
| 3891 | 3919 | gfunc_call(&gf); |
| 3892 | 3920 | vpushi(0); |
| 3893 | 3921 | vtop->r = REG_FRET; |
| @@ -3908,11 +3936,11 @@ void gen_cvt_ftoi1(int t) · 14 unmodified lines | ||
| 3908 | 3936 | st = vtop->t & VT_BTYPE; |
| 3909 | 3937 | gfunc_param(&gf); |
| 3910 | 3938 | if (st == VT_FLOAT) |
| 3911 | − vpush_sym(func_old_type, TOK___fixunssfdi); | |
| 3939 | + vpush_global_sym(func_old_type, TOK___fixunssfdi); | |
| 3912 | 3940 | else if (st == VT_DOUBLE) |
| 3913 | − vpush_sym(func_old_type, TOK___fixunsdfdi); | |
| 3941 | + vpush_global_sym(func_old_type, TOK___fixunsdfdi); | |
| 3914 | 3942 | else |
| 3915 | − vpush_sym(func_old_type, TOK___fixunsxfdi); | |
| 3943 | + vpush_global_sym(func_old_type, TOK___fixunsxfdi); | |
| 3916 | 3944 | gfunc_call(&gf); |
| 3917 | 3945 | vpushi(0); |
| 3918 | 3946 | vtop->r = REG_IRET; |
| @@ -4371,7 +4399,7 @@ void vstore(void) · 452 unmodified lines | ||
| 4371 | 4399 | gfunc_param(&gf); |
| 4372 | 4400 | |
| 4373 | 4401 | save_regs(0); |
| 4374 | − vpush_sym(func_old_type, TOK_memcpy); | |
| 4402 | + vpush_global_sym(func_old_type, TOK_memcpy); | |
| 4375 | 4403 | gfunc_call(&gf); |
| 4376 | 4404 | /* leave source on stack */ |
| 4377 | 4405 | } else if (ft & VT_BITFIELD) { |
| @@ -4950,21 +4978,6 @@ int type_decl(AttributeDef *ad, int *v, int t, int td) · 572 unmodified lines | ||
| 4950 | 4978 | return u; |
| 4951 | 4979 | } |
| 4952 | 4980 | |
| 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 | − | |
| 4968 | 4981 | /* compute the lvalue VT_LVAL_xxx needed to match type t. */ |
| 4969 | 4982 | static int lvalue_type(int t) |
| 4970 | 4983 | { |
| @@ -5115,7 +5128,7 @@ void unary(void) · 144 unmodified lines | ||
| 5115 | 5128 | } else |
| 5116 | 5129 | if (t == '!') { |
| 5117 | 5130 | unary(); |
| 5118 | − if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) | |
| 5131 | + if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) | |
| 5119 | 5132 | vtop->c.i = !vtop->c.i; |
| 5120 | 5133 | else if ((vtop->r & VT_VALMASK) == VT_CMP) |
| 5121 | 5134 | vtop->c.i = vtop->c.i ^ 1; |
| @@ -5172,7 +5185,7 @@ void unary(void) · 50 unmodified lines | ||
| 5172 | 5185 | error("'%s' undeclared", get_tok_str(t, NULL)); |
| 5173 | 5186 | /* for simple function calls, we tolerate undeclared |
| 5174 | 5187 | external reference to int() function */ |
| 5175 | − s = external_sym(t, func_old_type, 0); | |
| 5188 | + s = external_global_sym(t, func_old_type, 0); | |
| 5176 | 5189 | } |
| 5177 | 5190 | vset(s->t, s->r, s->c); |
| 5178 | 5191 | /* 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 | ||
| 5954 | 5967 | gfunc_param(&gf); |
| 5955 | 5968 | vset(VT_INT, VT_LOCAL, c); |
| 5956 | 5969 | gfunc_param(&gf); |
| 5957 | − vpush_sym(func_old_type, TOK_memset); | |
| 5970 | + vpush_global_sym(func_old_type, TOK_memset); | |
| 5958 | 5971 | gfunc_call(&gf); |
| 5959 | 5972 | } |
| 5960 | 5973 | } |