History

Tidy some code

the real difference is in decl0 where we can use external_sym just fine also for function definitions, we don't have to use external_global_sym. Setting VT_EXTERN in external_sym isn't necessary either (the type will have it set if necessary). The rest is tidying: removing unused arguments and moving some code around.

Michael Matz committed 7 years ago

Commit c07e81b1 parent f2461095 files · +20 −26Browse files

Unified · Split

5 files
  1. i386-gen.c +2 −2
  2. tcc.h +1 −1
  3. tccasm.c +1 −3
  4. tccgen.c +13 −17
  5. x86_64-gen.c +3 −3
i386-gen.c+2−2
@@ -341,7 +341,7 @@ static void gen_static_call(int v) · 340 unmodified lines
341{341{
342 Sym *sym;342 Sym *sym;
343 343
344 sym = external_global_sym(v, &func_old_type, 0);344 sym = external_global_sym(v, &func_old_type);
345 oad(0xe8, -4);345 oad(0xe8, -4);
346 greloc(cur_text_section, sym, ind-4, R_386_PC32);346 greloc(cur_text_section, sym, ind-4, R_386_PC32);
347}347}
@@ -1125,7 +1125,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) · 777 unmodified lines
1125 /* patch relocation */1125 /* patch relocation */
1126 /* XXX: find a better solution ? */1126 /* XXX: find a better solution ? */
1127 rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.i);1127 rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.i);
1128 sym = external_global_sym(func, &func_old_type, 0);1128 sym = external_global_sym(func, &func_old_type);
1129 if (!sym->c)1129 if (!sym->c)
1130 put_extern_sym(sym, NULL, 0, 0);1130 put_extern_sym(sym, NULL, 0, 0);
1131 rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info));1131 rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info));
tcc.h+1−1
@@ -1318,7 +1318,7 @@ ST_FUNC void test_lvalue(void); · 1317 unmodified lines
1318ST_FUNC void vpushi(int v);1318ST_FUNC void vpushi(int v);
1319ST_FUNC ElfSym *elfsym(Sym *);1319ST_FUNC ElfSym *elfsym(Sym *);
1320ST_FUNC void update_storage(Sym *sym);1320ST_FUNC void update_storage(Sym *sym);
1321ST_FUNC Sym *external_global_sym(int v, CType *type, int r);1321ST_FUNC Sym *external_global_sym(int v, CType *type);
1322ST_FUNC void vset(CType *type, int r, int v);1322ST_FUNC void vset(CType *type, int r, int v);
1323ST_FUNC void vswap(void);1323ST_FUNC void vswap(void);
1324ST_FUNC void vpush_global_sym(CType *type, int v);1324ST_FUNC void vpush_global_sym(CType *type, int v);
tccasm.c+1−3
@@ -48,9 +48,7 @@ static Sym *asm_label_push(int v) · 47 unmodified lines
48 /* We always add VT_EXTERN, for sym definition that's tentative48 /* We always add VT_EXTERN, for sym definition that's tentative
49 (for .set, removed for real defs), for mere references it's correct49 (for .set, removed for real defs), for mere references it's correct
50 as is. */50 as is. */
51 Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);51 return global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
52 sym->r = VT_CONST | VT_SYM;
53 return sym;
54}52}
55 53
56/* Return a symbol we can use inside the assembler, having name NAME.54/* Return a symbol we can use inside the assembler, having name NAME.
tccgen.c+13−17
@@ -616,11 +616,12 @@ ST_FUNC Sym *global_identifier_push(int v, int t, int c) · 615 unmodified lines
616{616{
617 Sym *s, **ps;617 Sym *s, **ps;
618 s = sym_push2(&global_stack, v, t, c);618 s = sym_push2(&global_stack, v, t, c);
619 s->r = VT_CONST | VT_SYM;
619 /* don't record anonymous symbol */620 /* don't record anonymous symbol */
620 if (v < SYM_FIRST_ANOM) {621 if (v < SYM_FIRST_ANOM) {
621 ps = &table_ident[v - TOK_IDENT]->sym_identifier;622 ps = &table_ident[v - TOK_IDENT]->sym_identifier;
622 /* modify the top most local identifier, so that623 /* modify the top most local identifier, so that sym_identifier will
623 sym_identifier will point to 's' when popped */624 point to 's' when popped; happens when called from inline asm */
624 while (*ps != NULL && (*ps)->sym_scope)625 while (*ps != NULL && (*ps)->sym_scope)
625 ps = &(*ps)->prev_tok;626 ps = &(*ps)->prev_tok;
626 s->prev_tok = *ps;627 s->prev_tok = *ps;
@@ -846,9 +847,8 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign · 219 unmodified lines
846 Sym *sym;847 Sym *sym;
847 848
848 v = anon_sym++;849 v = anon_sym++;
849 sym = global_identifier_push(v, type->t | VT_STATIC, 0);850 sym = sym_push(v, type, VT_CONST | VT_SYM, 0);
850 sym->type.ref = type->ref;851 sym->type.t |= VT_STATIC;
851 sym->r = VT_CONST | VT_SYM;
852 put_extern_sym(sym, sec, offset, size);852 put_extern_sym(sym, sec, offset, size);
853 return sym;853 return sym;
854}854}
@@ -860,7 +860,7 @@ static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned · 5 unmodified lines
860}860}
861 861
862/* define a new external reference to a symbol 'v' of type 'u' */862/* define a new external reference to a symbol 'v' of type 'u' */
863ST_FUNC Sym *external_global_sym(int v, CType *type, int r)863ST_FUNC Sym *external_global_sym(int v, CType *type)
864{864{
865 Sym *s;865 Sym *s;
866 866
@@ -869,7 +869,6 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r) · 2 unmodified lines
869 /* push forward reference */869 /* push forward reference */
870 s = global_identifier_push(v, type->t | VT_EXTERN, 0);870 s = global_identifier_push(v, type->t | VT_EXTERN, 0);
871 s->type.ref = type->ref;871 s->type.ref = type->ref;
872 s->r = r | VT_CONST | VT_SYM;
873 } else if (IS_ASM_SYM(s)) {872 } else if (IS_ASM_SYM(s)) {
874 s->type.t = type->t | (s->type.t & VT_EXTERN);873 s->type.t = type->t | (s->type.t & VT_EXTERN);
875 s->type.ref = type->ref;874 s->type.ref = type->ref;
@@ -1001,7 +1000,6 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 125 unmodified lines
1001 tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL));1000 tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL));
1002 /* push forward reference */1001 /* push forward reference */
1003 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);1002 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
1004 s->type.t |= VT_EXTERN;
1005 s->a = ad->a;1003 s->a = ad->a;
1006 s->sym_scope = 0;1004 s->sym_scope = 0;
1007 } else {1005 } else {
@@ -1018,7 +1016,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 10 unmodified lines
1018/* push a reference to global symbol v */1016/* push a reference to global symbol v */
1019ST_FUNC void vpush_global_sym(CType *type, int v)1017ST_FUNC void vpush_global_sym(CType *type, int v)
1020{1018{
1021 vpushsym(type, external_global_sym(v, type, 0));1019 vpushsym(type, external_global_sym(v, type));
1022}1020}
1023 1021
1024/* save registers up to (vtop - n) stack entry */1022/* save registers up to (vtop - n) stack entry */
@@ -3427,7 +3425,7 @@ redo: · 2402 unmodified lines
3427 if (!s) {3425 if (!s) {
3428 tcc_warning("implicit declaration of function '%s'",3426 tcc_warning("implicit declaration of function '%s'",
3429 get_tok_str(tok, &tokc));3427 get_tok_str(tok, &tokc));
3430 s = external_global_sym(tok, &func_old_type, 0);3428 s = external_global_sym(tok, &func_old_type);
3431 }3429 }
3432 ad->cleanup_func = s;3430 ad->cleanup_func = s;
3433 next();3431 next();
@@ -5258,7 +5256,7 @@ special_math_val: · 1824 unmodified lines
5258#endif5256#endif
5259 )5257 )
5260 tcc_warning("implicit declaration of function '%s'", name);5258 tcc_warning("implicit declaration of function '%s'", name);
5261 s = external_global_sym(t, &func_old_type, 0); 5259 s = external_global_sym(t, &func_old_type);
5262 }5260 }
5263 5261
5264 r = s->r;5262 r = s->r;
@@ -7265,8 +7263,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 2000 unmodified lines
7265 put_extern_sym(sym, sec, addr, size);7263 put_extern_sym(sym, sec, addr, size);
7266 } else {7264 } else {
7267 /* push global reference */7265 /* push global reference */
7268 sym = get_sym_ref(type, sec, addr, size);7266 vpush_ref(type, sec, addr, size);
7269 vpushsym(type, sym);7267 sym = vtop->sym;
7270 vtop->r |= r;7268 vtop->r |= r;
7271 }7269 }
7272 7270
@@ -7556,14 +7554,12 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 283 unmodified lines
7556 type.t = (type.t & ~VT_EXTERN) | VT_STATIC;7554 type.t = (type.t & ~VT_EXTERN) | VT_STATIC;
7557 7555
7558 /* put function symbol */7556 /* put function symbol */
7559 sym = external_global_sym(v, &type, 0);7557 sym = external_sym(v, &type, 0, &ad);
7560 type.t &= ~VT_EXTERN;
7561 patch_storage(sym, &ad, &type);
7562 7558
7563 /* static inline functions are just recorded as a kind7559 /* static inline functions are just recorded as a kind
7564 of macro. Their code will be emitted at the end of7560 of macro. Their code will be emitted at the end of
7565 the compilation unit only if they are used */7561 the compilation unit only if they are used */
7566 if ((type.t & (VT_INLINE | VT_STATIC)) == 7562 if ((type.t & (VT_INLINE | VT_STATIC)) ==
7567 (VT_INLINE | VT_STATIC)) {7563 (VT_INLINE | VT_STATIC)) {
7568 struct InlineFunc *fn;7564 struct InlineFunc *fn;
7569 const char *filename;7565 const char *filename;
x86_64-gen.c+3−3
@@ -649,7 +649,7 @@ static unsigned long func_bound_ind; · 648 unmodified lines
649 649
650static void gen_static_call(int v)650static void gen_static_call(int v)
651{651{
652 Sym *sym = external_global_sym(v, &func_old_type, 0);652 Sym *sym = external_global_sym(v, &func_old_type);
653 oad(0xe8, 0);653 oad(0xe8, 0);
654 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);654 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
655}655}
@@ -713,7 +713,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) · 57 unmodified lines
713 break;713 break;
714 }714 }
715 715
716 sym = external_global_sym(func, &func_old_type, 0);716 sym = external_global_sym(func, &func_old_type);
717 if (!sym->c)717 if (!sym->c)
718 put_extern_sym(sym, NULL, 0, 0);718 put_extern_sym(sym, NULL, 0, 0);
719 719
@@ -1031,7 +1031,7 @@ void gfunc_epilog(void) · 311 unmodified lines
1031 v = (func_scratch + -loc + 15) & -16;1031 v = (func_scratch + -loc + 15) & -16;
1032 1032
1033 if (v >= 4096) {1033 if (v >= 4096) {
1034 Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0);1034 Sym *sym = external_global_sym(TOK___chkstk, &func_old_type);
1035 oad(0xb8, v); /* mov stacksize, %eax */1035 oad(0xb8, v); /* mov stacksize, %eax */
1036 oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */1036 oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */
1037 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);1037 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);

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