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
341341 {
342342 Sym *sym;
343343
344− sym = external_global_sym(v, &func_old_type, 0);
344+ sym = external_global_sym(v, &func_old_type);
345345 oad(0xe8, -4);
346346 greloc(cur_text_section, sym, ind-4, R_386_PC32);
347347 }
@@ -1125,7 +1125,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) · 777 unmodified lines
11251125 /* patch relocation */
11261126 /* XXX: find a better solution ? */
11271127 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);
11291129 if (!sym->c)
11301130 put_extern_sym(sym, NULL, 0, 0);
11311131 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
13181318 ST_FUNC void vpushi(int v);
13191319 ST_FUNC ElfSym *elfsym(Sym *);
13201320 ST_FUNC void update_storage(Sym *sym);
1321−ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
1321+ST_FUNC Sym *external_global_sym(int v, CType *type);
13221322 ST_FUNC void vset(CType *type, int r, int v);
13231323 ST_FUNC void vswap(void);
13241324 ST_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
4848 /* We always add VT_EXTERN, for sym definition that's tentative
4949 (for .set, removed for real defs), for mere references it's correct
5050 as is. */
51− Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
52− sym->r = VT_CONST | VT_SYM;
53− return sym;
51+ return global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
5452 }
5553
5654 /* 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
616616 {
617617 Sym *s, **ps;
618618 s = sym_push2(&global_stack, v, t, c);
619+ s->r = VT_CONST | VT_SYM;
619620 /* don't record anonymous symbol */
620621 if (v < SYM_FIRST_ANOM) {
621622 ps = &table_ident[v - TOK_IDENT]->sym_identifier;
622− /* modify the top most local identifier, so that
623− sym_identifier will point to 's' when popped */
623+ /* modify the top most local identifier, so that sym_identifier will
624+ point to 's' when popped; happens when called from inline asm */
624625 while (*ps != NULL && (*ps)->sym_scope)
625626 ps = &(*ps)->prev_tok;
626627 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
846847 Sym *sym;
847848
848849 v = anon_sym++;
849− sym = global_identifier_push(v, type->t | VT_STATIC, 0);
850− sym->type.ref = type->ref;
851− sym->r = VT_CONST | VT_SYM;
850+ sym = sym_push(v, type, VT_CONST | VT_SYM, 0);
851+ sym->type.t |= VT_STATIC;
852852 put_extern_sym(sym, sec, offset, size);
853853 return sym;
854854 }
@@ -860,7 +860,7 @@ static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned · 5 unmodified lines
860860 }
861861
862862 /* define a new external reference to a symbol 'v' of type 'u' */
863−ST_FUNC Sym *external_global_sym(int v, CType *type, int r)
863+ST_FUNC Sym *external_global_sym(int v, CType *type)
864864 {
865865 Sym *s;
866866
@@ -869,7 +869,6 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r) · 2 unmodified lines
869869 /* push forward reference */
870870 s = global_identifier_push(v, type->t | VT_EXTERN, 0);
871871 s->type.ref = type->ref;
872− s->r = r | VT_CONST | VT_SYM;
873872 } else if (IS_ASM_SYM(s)) {
874873 s->type.t = type->t | (s->type.t & VT_EXTERN);
875874 s->type.ref = type->ref;
@@ -1001,7 +1000,6 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 125 unmodified lines
10011000 tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL));
10021001 /* push forward reference */
10031002 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
1004− s->type.t |= VT_EXTERN;
10051003 s->a = ad->a;
10061004 s->sym_scope = 0;
10071005 } else {
@@ -1018,7 +1016,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 10 unmodified lines
10181016 /* push a reference to global symbol v */
10191017 ST_FUNC void vpush_global_sym(CType *type, int v)
10201018 {
1021− vpushsym(type, external_global_sym(v, type, 0));
1019+ vpushsym(type, external_global_sym(v, type));
10221020 }
10231021
10241022 /* save registers up to (vtop - n) stack entry */
@@ -3427,7 +3425,7 @@ redo: · 2402 unmodified lines
34273425 if (!s) {
34283426 tcc_warning("implicit declaration of function '%s'",
34293427 get_tok_str(tok, &tokc));
3430− s = external_global_sym(tok, &func_old_type, 0);
3428+ s = external_global_sym(tok, &func_old_type);
34313429 }
34323430 ad->cleanup_func = s;
34333431 next();
@@ -5258,7 +5256,7 @@ special_math_val: · 1824 unmodified lines
52585256 #endif
52595257 )
52605258 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);
52625260 }
52635261
52645262 r = s->r;
@@ -7265,8 +7263,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 2000 unmodified lines
72657263 put_extern_sym(sym, sec, addr, size);
72667264 } else {
72677265 /* push global reference */
7268− sym = get_sym_ref(type, sec, addr, size);
7269− vpushsym(type, sym);
7266+ vpush_ref(type, sec, addr, size);
7267+ sym = vtop->sym;
72707268 vtop->r |= r;
72717269 }
72727270
@@ -7556,14 +7554,12 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 283 unmodified lines
75567554 type.t = (type.t & ~VT_EXTERN) | VT_STATIC;
75577555
75587556 /* put function symbol */
7559− sym = external_global_sym(v, &type, 0);
7560− type.t &= ~VT_EXTERN;
7561− patch_storage(sym, &ad, &type);
7557+ sym = external_sym(v, &type, 0, &ad);
75627558
75637559 /* static inline functions are just recorded as a kind
75647560 of macro. Their code will be emitted at the end of
75657561 the compilation unit only if they are used */
7566− if ((type.t & (VT_INLINE | VT_STATIC)) ==
7562+ if ((type.t & (VT_INLINE | VT_STATIC)) ==
75677563 (VT_INLINE | VT_STATIC)) {
75687564 struct InlineFunc *fn;
75697565 const char *filename;
x86_64-gen.c+3−3
@@ -649,7 +649,7 @@ static unsigned long func_bound_ind; · 648 unmodified lines
649649
650650 static void gen_static_call(int v)
651651 {
652− Sym *sym = external_global_sym(v, &func_old_type, 0);
652+ Sym *sym = external_global_sym(v, &func_old_type);
653653 oad(0xe8, 0);
654654 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
655655 }
@@ -713,7 +713,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) · 57 unmodified lines
713713 break;
714714 }
715715
716− sym = external_global_sym(func, &func_old_type, 0);
716+ sym = external_global_sym(func, &func_old_type);
717717 if (!sym->c)
718718 put_extern_sym(sym, NULL, 0, 0);
719719
@@ -1031,7 +1031,7 @@ void gfunc_epilog(void) · 311 unmodified lines
10311031 v = (func_scratch + -loc + 15) & -16;
10321032
10331033 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);
10351035 oad(0xb8, v); /* mov stacksize, %eax */
10361036 oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */
10371037 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