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