History

tccgen: nocode_wanted alternatively

tccgen.c: remove any 'nocode_wanted' checks, except in - greloca(), disables output elf symbols and relocs - get_reg(), will return just the first suitable reg) - save_regs(), will do nothing Some minor adjustments were made where nocode_wanted is set. xxx-gen.c: disable code output directly where it happens in functions: - g(), output disabled - gjmp(), will do nothing - gtst(), dto.

grischka committed 9 years ago

Commit f843cad1 parent 77d7ea07 files · +111 −131Browse files

Unified · Split

7 files
  1. arm-gen.c +9 −2
  2. arm64-gen.c +4 −0
  3. c67-gen.c +7 −2
  4. i386-gen.c +15 −18
  5. tccasm.c +6 −1
  6. tccgen.c +52 −92
  7. x86_64-gen.c +18 −16
arm-gen.c+9−2
@@ -214,7 +214,8 @@ void o(uint32_t i) · 213 unmodified lines
214{214{
215 /* this is a good place to start adding big-endian support*/215 /* this is a good place to start adding big-endian support*/
216 int ind1;216 int ind1;
217 217 if (nocode_wanted)
218 return;
218 ind1 = ind + 4;219 ind1 = ind + 4;
219 if (!cur_text_section)220 if (!cur_text_section)
220 tcc_error("compiler error! This happens f.ex. if the compiler\n"221 tcc_error("compiler error! This happens f.ex. if the compiler\n"
@@ -1411,6 +1412,8 @@ void gfunc_epilog(void) · 1190 unmodified lines
1411int gjmp(int t)1412int gjmp(int t)
1412{1413{
1413 int r;1414 int r;
1415 if (nocode_wanted)
1416 return t;
1414 r=ind;1417 r=ind;
1415 o(0xE0000000|encbranch(r,t,1));1418 o(0xE0000000|encbranch(r,t,1));
1416 return r;1419 return r;
@@ -1427,9 +1430,13 @@ int gtst(int inv, int t) · 10 unmodified lines
1427{1430{
1428 int v, r;1431 int v, r;
1429 uint32_t op;1432 uint32_t op;
1433
1430 v = vtop->r & VT_VALMASK;1434 v = vtop->r & VT_VALMASK;
1431 r=ind;1435 r=ind;
1432 if (v == VT_CMP) {1436
1437 if (nocode_wanted) {
1438 ;
1439 } else if (v == VT_CMP) {
1433 op=mapcc(inv?negcc(vtop->c.i):vtop->c.i);1440 op=mapcc(inv?negcc(vtop->c.i):vtop->c.i);
1434 op|=encbranch(r,t,1);1441 op|=encbranch(r,t,1);
1435 o(op);1442 o(op);
arm64-gen.c+4−0
@@ -95,6 +95,8 @@ static uint32_t fltr(int r) · 94 unmodified lines
95ST_FUNC void o(unsigned int c)95ST_FUNC void o(unsigned int c)
96{96{
97 int ind1 = ind + 4;97 int ind1 = ind + 4;
98 if (nocode_wanted)
99 return;
98 if (ind1 > cur_text_section->data_allocated)100 if (ind1 > cur_text_section->data_allocated)
99 section_realloc(cur_text_section, ind1);101 section_realloc(cur_text_section, ind1);
100 write32le(cur_text_section->data + ind, c);102 write32le(cur_text_section->data + ind, c);
@@ -1278,6 +1280,8 @@ ST_FUNC void gfunc_epilog(void) · 1177 unmodified lines
1278ST_FUNC int gjmp(int t)1280ST_FUNC int gjmp(int t)
1279{1281{
1280 int r = ind;1282 int r = ind;
1283 if (nocode_wanted)
1284 return t;
1281 o(t);1285 o(t);
1282 return r;1286 return r;
1283}1287}
c67-gen.c+7−2
@@ -182,7 +182,8 @@ FILE *f = NULL; · 181 unmodified lines
182void C67_g(int c)182void C67_g(int c)
183{183{
184 int ind1;184 int ind1;
185 185 if (nocode_wanted)
186 return;
186#ifdef ASSEMBLY_LISTING_C67187#ifdef ASSEMBLY_LISTING_C67
187 fprintf(f, " %08X", c);188 fprintf(f, " %08X", c);
188#endif189#endif
@@ -2038,6 +2039,8 @@ void gfunc_epilog(void) · 1849 unmodified lines
2038int gjmp(int t)2039int gjmp(int t)
2039{2040{
2040 int ind1 = ind;2041 int ind1 = ind;
2042 if (nocode_wanted)
2043 return t;
2041 2044
2042 C67_MVKL(C67_A0, t); //r=reg to load, constant2045 C67_MVKL(C67_A0, t); //r=reg to load, constant
2043 C67_MVKH(C67_A0, t); //r=reg to load, constant2046 C67_MVKH(C67_A0, t); //r=reg to load, constant
@@ -2070,7 +2073,9 @@ int gtst(int inv, int t) · 26 unmodified lines
2070 int v, *p;2073 int v, *p;
2071 2074
2072 v = vtop->r & VT_VALMASK;2075 v = vtop->r & VT_VALMASK;
2073 if (v == VT_CMP) {2076 if (nocode_wanted) {
2077 ;
2078 } else if (v == VT_CMP) {
2074 /* fast case : can jump directly since flags are set */2079 /* fast case : can jump directly since flags are set */
2075 // C67 uses B2 sort of as flags register2080 // C67 uses B2 sort of as flags register
2076 ind1 = ind;2081 ind1 = ind;
i386-gen.c+15−18
@@ -70,8 +70,8 @@ enum { · 69 unmodified lines
70/* maximum alignment (for aligned attribute support) */70/* maximum alignment (for aligned attribute support) */
71#define MAX_ALIGN 871#define MAX_ALIGN 8
72 72
73 73/* generate jmp to a label */
74#define psym oad74#define gjmp2(instr,lbl) oad(instr,lbl)
75 75
76/******************************************************/76/******************************************************/
77#else /* ! TARGET_DEFS_ONLY */77#else /* ! TARGET_DEFS_ONLY */
@@ -100,6 +100,8 @@ static unsigned long func_bound_ind; · 22 unmodified lines
100ST_FUNC void g(int c)100ST_FUNC void g(int c)
101{101{
102 int ind1;102 int ind1;
103 if (nocode_wanted)
104 return;
103 ind1 = ind + 1;105 ind1 = ind + 1;
104 if (ind1 > cur_text_section->data_allocated)106 if (ind1 > cur_text_section->data_allocated)
105 section_realloc(cur_text_section, ind1);107 section_realloc(cur_text_section, ind1);
@@ -145,23 +147,16 @@ ST_FUNC void gsym(int t) · 39 unmodified lines
145 gsym_addr(t, ind);147 gsym_addr(t, ind);
146}148}
147 149
148/* psym is used to put an instruction with a data field which is a
149 reference to a symbol. It is in fact the same as oad ! */
150#define psym oad
151
152/* instruction + 4 bytes data. Return the address of the data */150/* instruction + 4 bytes data. Return the address of the data */
153ST_FUNC int oad(int c, int s)151ST_FUNC int oad(int c, int s)
154{152{
155 int ind1;153 int t;
156 154 if (nocode_wanted)
155 return s;
157 o(c);156 o(c);
158 ind1 = ind + 4;157 t = ind;
159 if (ind1 > cur_text_section->data_allocated)158 gen_le32(s);
160 section_realloc(cur_text_section, ind1);159 return t;
161 write32le(cur_text_section->data + ind, s);
162 s = ind;
163 ind = ind1;
164 return s;
165}160}
166 161
167/* output constant with relocation if 'r & VT_SYM' is true */162/* output constant with relocation if 'r & VT_SYM' is true */
@@ -676,7 +671,7 @@ ST_FUNC void gfunc_epilog(void) · 508 unmodified lines
676/* generate a jump to a label */671/* generate a jump to a label */
677ST_FUNC int gjmp(int t)672ST_FUNC int gjmp(int t)
678{673{
679 return psym(0xe9, t);674 return gjmp2(0xe9, t);
680}675}
681 676
682/* generate a jump to a fixed address */677/* generate a jump to a fixed address */
@@ -722,10 +717,12 @@ ST_FUNC void gtst_addr(int inv, int a) · 39 unmodified lines
722ST_FUNC int gtst(int inv, int t)717ST_FUNC int gtst(int inv, int t)
723{718{
724 int v = vtop->r & VT_VALMASK;719 int v = vtop->r & VT_VALMASK;
725 if (v == VT_CMP) {720 if (nocode_wanted) {
721 ;
722 } else if (v == VT_CMP) {
726 /* fast case : can jump directly since flags are set */723 /* fast case : can jump directly since flags are set */
727 g(0x0f);724 g(0x0f);
728 t = psym((vtop->c.i - 16) ^ inv, t);725 t = gjmp2((vtop->c.i - 16) ^ inv, t);
729 } else if (v == VT_JMP || v == VT_JMPI) {726 } else if (v == VT_JMP || v == VT_JMPI) {
730 /* && or || optimization */727 /* && or || optimization */
731 if ((v & 1) == inv) {728 if ((v & 1) == inv) {
tccasm.c+6−1
@@ -915,8 +915,12 @@ static void asm_parse_directive(TCCState *s1) · 914 unmodified lines
915/* assemble a file */915/* assemble a file */
916static int tcc_assemble_internal(TCCState *s1, int do_preprocess)916static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
917{917{
918 int saved_nocode_wanted;
918 int opcode;919 int opcode;
919 920
921 saved_nocode_wanted = nocode_wanted;
922 nocode_wanted = 0;
923
920 /* XXX: undefine C labels */924 /* XXX: undefine C labels */
921 925
922 ch = file->buf_ptr[0];926 ch = file->buf_ptr[0];
@@ -960,7 +964,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 37 unmodified lines
960 /* handle "extern void vide(void); __asm__("vide: ret");" as964 /* handle "extern void vide(void); __asm__("vide: ret");" as
961 "__asm__("globl vide\nvide: ret");" */965 "__asm__("globl vide\nvide: ret");" */
962 Sym *sym = sym_find(opcode);966 Sym *sym = sym_find(opcode);
963 if (sym && (sym->type.t & VT_EXTERN) && nocode_wanted) {967 if (sym && (sym->type.t & VT_EXTERN) && saved_nocode_wanted) {
964 sym = label_find(opcode);968 sym = label_find(opcode);
965 if (!sym) {969 if (!sym) {
966 sym = label_push(&s1->asm_labels, opcode, 0);970 sym = label_push(&s1->asm_labels, opcode, 0);
@@ -989,6 +993,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 22 unmodified lines
989 993
990 asm_free_labels(s1);994 asm_free_labels(s1);
991 995
996 nocode_wanted = saved_nocode_wanted;
992 return 0;997 return 0;
993}998}
994 999
tccgen.c+52−92
@@ -69,6 +69,7 @@ ST_DATA struct switch_t { · 68 unmodified lines
69} *cur_switch; /* current switch */69} *cur_switch; /* current switch */
70 70
71/* ------------------------------------------------------------------------- */71/* ------------------------------------------------------------------------- */
72
72static void gen_cast(CType *type);73static void gen_cast(CType *type);
73static inline CType *pointed_type(CType *type);74static inline CType *pointed_type(CType *type);
74static int is_compatible_types(CType *type1, CType *type2);75static int is_compatible_types(CType *type1, CType *type2);
@@ -322,11 +323,16 @@ ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, · 247 unmodified lines
322 addr_t addend)323 addr_t addend)
323{324{
324 int c = 0;325 int c = 0;
326
327 if (nocode_wanted && s == cur_text_section)
328 return;
329
325 if (sym) {330 if (sym) {
326 if (0 == sym->c)331 if (0 == sym->c)
327 put_extern_sym(sym, NULL, 0, 0);332 put_extern_sym(sym, NULL, 0, 0);
328 c = sym->c;333 c = sym->c;
329 }334 }
335
330 /* now we can add ELF relocation info */336 /* now we can add ELF relocation info */
331 put_elf_reloca(symtab_section, s, offset, type, c, addend);337 put_elf_reloca(symtab_section, s, offset, type, c, addend);
332}338}
@@ -774,6 +780,8 @@ ST_FUNC void save_reg_upstack(int r, int n) · 441 unmodified lines
774 780
775 if ((r &= VT_VALMASK) >= VT_CONST)781 if ((r &= VT_VALMASK) >= VT_CONST)
776 return;782 return;
783 if (nocode_wanted)
784 return;
777 785
778 /* modify all stack values */786 /* modify all stack values */
779 saved = 0;787 saved = 0;
@@ -865,6 +873,8 @@ ST_FUNC int get_reg(int rc) · 85 unmodified lines
865 /* find a free register */873 /* find a free register */
866 for(r=0;r<NB_REGS;r++) {874 for(r=0;r<NB_REGS;r++) {
867 if (reg_classes[r] & rc) {875 if (reg_classes[r] & rc) {
876 if (nocode_wanted)
877 return r;
868 for(p=vstack;p<=vtop;p++) {878 for(p=vstack;p<=vtop;p++) {
869 if ((p->r & VT_VALMASK) == r ||879 if ((p->r & VT_VALMASK) == r ||
870 (p->r2 & VT_VALMASK) == r)880 (p->r2 & VT_VALMASK) == r)
@@ -913,7 +923,7 @@ static void move_reg(int r, int s, int t) · 42 unmodified lines
913/* get address of vtop (vtop MUST BE an lvalue) */923/* get address of vtop (vtop MUST BE an lvalue) */
914ST_FUNC void gaddrof(void)924ST_FUNC void gaddrof(void)
915{925{
916 if (vtop->r & VT_REF && !nocode_wanted)926 if (vtop->r & VT_REF)
917 gv(RC_INT);927 gv(RC_INT);
918 vtop->r &= ~VT_LVAL;928 vtop->r &= ~VT_LVAL;
919 /* tricky: if saved lvalue, then we can go back to lvalue */929 /* tricky: if saved lvalue, then we can go back to lvalue */
@@ -1317,7 +1327,7 @@ ST_FUNC void vpop(void) · 397 unmodified lines
1317 v = vtop->r & VT_VALMASK;1327 v = vtop->r & VT_VALMASK;
1318#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)1328#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
1319 /* for x86, we need to pop the FP stack */1329 /* for x86, we need to pop the FP stack */
1320 if (v == TREG_ST0 && !nocode_wanted) {1330 if (v == TREG_ST0) {
1321 o(0xd8dd); /* fstp %st(0) */1331 o(0xd8dd); /* fstp %st(0) */
1322 } else1332 } else
1323#endif1333#endif
@@ -1607,7 +1617,7 @@ static void gen_opl(int op) · 283 unmodified lines
1607 b = gvtst(0, 0);1617 b = gvtst(0, 0);
1608 } else {1618 } else {
1609#if defined(TCC_TARGET_I386)1619#if defined(TCC_TARGET_I386)
1610 b = psym(0x850f, 0);1620 b = gjmp2(0x850f, 0);
1611#elif defined(TCC_TARGET_ARM)1621#elif defined(TCC_TARGET_ARM)
1612 b = ind;1622 b = ind;
1613 o(0x1A000000 | encbranch(ind, 0, 1));1623 o(0x1A000000 | encbranch(ind, 0, 1));
@@ -1789,23 +1799,12 @@ static void gen_opic(int op) · 175 unmodified lines
1789 vtop->c.i = l2;1799 vtop->c.i = l2;
1790 } else {1800 } else {
1791 general_case:1801 general_case:
1792 if (!nocode_wanted) {
1793 /* call low level op generator */1802 /* call low level op generator */
1794 if (t1 == VT_LLONG || t2 == VT_LLONG ||1803 if (t1 == VT_LLONG || t2 == VT_LLONG ||
1795 (PTR_SIZE == 8 && (t1 == VT_PTR || t2 == VT_PTR)))1804 (PTR_SIZE == 8 && (t1 == VT_PTR || t2 == VT_PTR)))
1796 gen_opl(op);1805 gen_opl(op);
1797 else1806 else
1798 gen_opi(op);1807 gen_opi(op);
1799 } else {
1800 vtop--;
1801 /* Ensure vtop isn't marked VT_CONST in case something
1802 up our callchain is interested in const-ness of the
1803 expression. Also make it a non-LVAL if it was,
1804 so that further code can't accidentally generate
1805 a deref (happen only for buggy uses of e.g.
1806 gv() under nocode_wanted). */
1807 vtop->r &= ~(VT_VALMASK | VT_LVAL);
1808 }
1809 }1808 }
1810 }1809 }
1811}1810}
@@ -1866,11 +1865,7 @@ static void gen_opif(int op) · 54 unmodified lines
1866 vtop--;1865 vtop--;
1867 } else {1866 } else {
1868 general_case:1867 general_case:
1869 if (!nocode_wanted) {1868 gen_opf(op);
1870 gen_opf(op);
1871 } else {
1872 vtop--;
1873 }
1874 }1869 }
1875}1870}
1876 1871
@@ -2149,7 +2144,7 @@ redo: · 272 unmodified lines
2149 }2144 }
2150 }2145 }
2151 // Make sure that we have converted to an rvalue:2146 // Make sure that we have converted to an rvalue:
2152 if (vtop->r & VT_LVAL && !nocode_wanted)2147 if (vtop->r & VT_LVAL)
2153 gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT);2148 gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT);
2154}2149}
2155 2150
@@ -2255,7 +2250,7 @@ static void gen_cast(CType *type) · 99 unmodified lines
2255 }2250 }
2256 2251
2257 /* bitfields first get cast to ints */2252 /* bitfields first get cast to ints */
2258 if (vtop->type.t & VT_BITFIELD && !nocode_wanted) {2253 if (vtop->type.t & VT_BITFIELD) {
2259 gv(RC_INT);2254 gv(RC_INT);
2260 }2255 }
2261 2256
@@ -2331,7 +2326,7 @@ static void gen_cast(CType *type) · 69 unmodified lines
2331 } else if (p && dbt == VT_BOOL) {2326 } else if (p && dbt == VT_BOOL) {
2332 vtop->r = VT_CONST;2327 vtop->r = VT_CONST;
2333 vtop->c.i = 1;2328 vtop->c.i = 1;
2334 } else if (!nocode_wanted) {2329 } else {
2335 /* non constant case: generate code */2330 /* non constant case: generate code */
2336 if (sf && df) {2331 if (sf && df) {
2337 /* convert from fp to fp */2332 /* convert from fp to fp */
@@ -2883,7 +2878,6 @@ ST_FUNC void vstore(void) · 545 unmodified lines
2883 /* if structure, only generate pointer */2878 /* if structure, only generate pointer */
2884 /* structure assignment : generate memcpy */2879 /* structure assignment : generate memcpy */
2885 /* XXX: optimize if small size */2880 /* XXX: optimize if small size */
2886 if (!nocode_wanted) {
2887 size = type_size(&vtop->type, &align);2881 size = type_size(&vtop->type, &align);
2888 2882
2889 /* destination */2883 /* destination */
@@ -2910,10 +2904,7 @@ ST_FUNC void vstore(void) · 20 unmodified lines
2910 /* type size */2904 /* type size */
2911 vpushi(size);2905 vpushi(size);
2912 gfunc_call(3);2906 gfunc_call(3);
2913 } else {2907
2914 vswap();
2915 vpop();
2916 }
2917 /* leave source on stack */2908 /* leave source on stack */
2918 } else if (ft & VT_BITFIELD) {2909 } else if (ft & VT_BITFIELD) {
2919 /* bitfield store handling */2910 /* bitfield store handling */
@@ -2961,7 +2952,6 @@ ST_FUNC void vstore(void) · 41 unmodified lines
2961 vpop();2952 vpop();
2962 2953
2963 } else {2954 } else {
2964 if (!nocode_wanted) {
2965#ifdef CONFIG_TCC_BCHECK2955#ifdef CONFIG_TCC_BCHECK
2966 /* bound check case */2956 /* bound check case */
2967 if (vtop[-1].r & VT_MUSTBOUND) {2957 if (vtop[-1].r & VT_MUSTBOUND) {
@@ -3020,7 +3010,7 @@ ST_FUNC void vstore(void) · 52 unmodified lines
3020 } else {3010 } else {
3021 store(r, vtop - 1);3011 store(r, vtop - 1);
3022 }3012 }
3023 }3013
3024 vswap();3014 vswap();
3025 vtop--; /* NOT vpop() because on x86 it would flush the fp stack */3015 vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
3026 vtop->r |= delayed_cast;3016 vtop->r |= delayed_cast;
@@ -3033,10 +3023,7 @@ ST_FUNC void inc(int post, int c) · 6 unmodified lines
3033 test_lvalue();3023 test_lvalue();
3034 vdup(); /* save lvalue */3024 vdup(); /* save lvalue */
3035 if (post) {3025 if (post) {
3036 if (!nocode_wanted)3026 gv_dup(); /* duplicate value */
3037 gv_dup(); /* duplicate value */
3038 else
3039 vdup(); /* duplicate value */
3040 vrotb(3);3027 vrotb(3);
3041 vrotb(3);3028 vrotb(3);
3042 }3029 }
@@ -4189,7 +4176,7 @@ ST_FUNC void indir(void) · 1146 unmodified lines
4189 return;4176 return;
4190 expect("pointer");4177 expect("pointer");
4191 }4178 }
4192 if ((vtop->r & VT_LVAL) && !nocode_wanted)4179 if (vtop->r & VT_LVAL)
4193 gv(RC_INT);4180 gv(RC_INT);
4194 vtop->type = *pointed_type(&vtop->type);4181 vtop->type = *pointed_type(&vtop->type);
4195 /* Arrays and functions are never lvalues */4182 /* Arrays and functions are never lvalues */
@@ -4382,8 +4369,7 @@ ST_FUNC void unary(void) · 186 unmodified lines
4382 if (const_wanted)4369 if (const_wanted)
4383 tcc_error("expected constant");4370 tcc_error("expected constant");
4384 /* save all registers */4371 /* save all registers */
4385 if (!nocode_wanted)4372 save_regs(0);
4386 save_regs(0);
4387 /* statement expression : we do not accept break/continue4373 /* statement expression : we do not accept break/continue
4388 inside as GCC does */4374 inside as GCC does */
4389 block(NULL, NULL, 1);4375 block(NULL, NULL, 1);
@@ -4610,8 +4596,6 @@ ST_FUNC void unary(void) · 220 unmodified lines
4610 4596
4611#ifdef TCC_TARGET_ARM644597#ifdef TCC_TARGET_ARM64
4612 case TOK___va_start: {4598 case TOK___va_start: {
4613 if (nocode_wanted)
4614 tcc_error("statement in global scope");
4615 next();4599 next();
4616 skip('(');4600 skip('(');
4617 expr_eq();4601 expr_eq();
@@ -4626,8 +4610,6 @@ ST_FUNC void unary(void) · 8 unmodified lines
4626 }4610 }
4627 case TOK___va_arg: {4611 case TOK___va_arg: {
4628 CType type;4612 CType type;
4629 if (nocode_wanted)
4630 tcc_error("statement in global scope");
4631 next();4613 next();
4632 skip('(');4614 skip('(');
4633 expr_eq();4615 expr_eq();
@@ -4906,11 +4888,7 @@ ST_FUNC void unary(void) · 272 unmodified lines
4906 if (sa)4888 if (sa)
4907 tcc_error("too few arguments to function");4889 tcc_error("too few arguments to function");
4908 skip(')');4890 skip(')');
4909 if (!nocode_wanted) {4891 gfunc_call(nb_args);
4910 gfunc_call(nb_args);
4911 } else {
4912 vtop -= (nb_args + 1);
4913 }
4914 4892
4915 /* return value */4893 /* return value */
4916 for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {4894 for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {
@@ -5083,9 +5061,9 @@ static void expr_land(void) · 166 unmodified lines
5083 expr_or();5061 expr_or();
5084 vpop();5062 vpop();
5085 }5063 }
5064 nocode_wanted = saved_nocode_wanted;
5086 if (t)5065 if (t)
5087 gsym(t);5066 gsym(t);
5088 nocode_wanted = saved_nocode_wanted;
5089 gen_cast(&int_type);5067 gen_cast(&int_type);
5090 break;5068 break;
5091 }5069 }
@@ -5127,9 +5105,9 @@ static void expr_lor(void) · 35 unmodified lines
5127 expr_land();5105 expr_land();
5128 vpop();5106 vpop();
5129 }5107 }
5108 nocode_wanted = saved_nocode_wanted;
5130 if (t)5109 if (t)
5131 gsym(t);5110 gsym(t);
5132 nocode_wanted = saved_nocode_wanted;
5133 gen_cast(&int_type);5111 gen_cast(&int_type);
5134 break;5112 break;
5135 }5113 }
@@ -5206,16 +5184,6 @@ static void expr_cond(void) · 70 unmodified lines
5206 }5184 }
5207 }5185 }
5208 else {5186 else {
5209 /* XXX This doesn't handle nocode_wanted correctly at all.
5210 It unconditionally calls gv/gvtst and friends. That's
5211 the case for many of the expr_ routines. Currently
5212 that should generate only useless code, but depending
5213 on other operand handling this might also generate
5214 pointer derefs for lvalue conversions whose result
5215 is useless, but nevertheless can lead to segfault.
5216
5217 Somewhen we need to overhaul the whole nocode_wanted
5218 handling. */
5219 if (vtop != vstack) {5187 if (vtop != vstack) {
5220 /* needed to avoid having different registers saved in5188 /* needed to avoid having different registers saved in
5221 each branch */5189 each branch */
@@ -5575,19 +5543,22 @@ static void block(int *bsym, int *csym, int is_expr) · 353 unmodified lines
5575 gexpr();5543 gexpr();
5576 skip(')');5544 skip(')');
5577 cond = condition_3way();5545 cond = condition_3way();
5578 if (cond == 0)5546 if (cond == 1)
5547 a = 0, vpop();
5548 else
5549 a = gvtst(1, 0);
5550 if (cond == 0)
5579 nocode_wanted |= 2;5551 nocode_wanted |= 2;
5580 a = gvtst(1, 0);
5581 block(bsym, csym, 0);5552 block(bsym, csym, 0);
5582 if (cond != 1)5553 if (cond != 1)
5583 nocode_wanted = saved_nocode_wanted;5554 nocode_wanted = saved_nocode_wanted;
5584 c = tok;5555 c = tok;
5585 if (c == TOK_ELSE) {5556 if (c == TOK_ELSE) {
5586 next();5557 next();
5587 if (cond == 1)
5588 nocode_wanted |= 2;
5589 d = gjmp(0);5558 d = gjmp(0);
5590 gsym(a);5559 gsym(a);
5560 if (cond == 1)
5561 nocode_wanted |= 2;
5591 block(bsym, csym, 0);5562 block(bsym, csym, 0);
5592 gsym(d); /* patch else jmp */5563 gsym(d); /* patch else jmp */
5593 if (cond != 0)5564 if (cond != 0)
@@ -5610,8 +5581,7 @@ static void block(int *bsym, int *csym, int is_expr) · 16 unmodified lines
5610 block(&a, &b, 0);5581 block(&a, &b, 0);
5611 nocode_wanted = saved_nocode_wanted;5582 nocode_wanted = saved_nocode_wanted;
5612 --local_scope;5583 --local_scope;
5613 if(!nocode_wanted)5584 gjmp_addr(d);
5614 gjmp_addr(d);
5615 gsym(a);5585 gsym(a);
5616 gsym_addr(b, d);5586 gsym_addr(b, d);
5617 } else if (tok == '{') {5587 } else if (tok == '{') {
@@ -5801,8 +5771,7 @@ static void block(int *bsym, int *csym, int is_expr) · 183 unmodified lines
5801 saved_nocode_wanted = nocode_wanted;5771 saved_nocode_wanted = nocode_wanted;
5802 block(&a, &b, 0);5772 block(&a, &b, 0);
5803 nocode_wanted = saved_nocode_wanted;5773 nocode_wanted = saved_nocode_wanted;
5804 if(!nocode_wanted)5774 gjmp_addr(c);
5805 gjmp_addr(c);
5806 gsym(a);5775 gsym(a);
5807 gsym_addr(b, c);5776 gsym_addr(b, c);
5808 --local_scope;5777 --local_scope;
@@ -5823,11 +5792,8 @@ static void block(int *bsym, int *csym, int is_expr) · 14 unmodified lines
5823 skip('(');5792 skip('(');
5824 gsym(b);5793 gsym(b);
5825 gexpr();5794 gexpr();
5826 if (!nocode_wanted) {5795 c = gvtst(0, 0);
5827 c = gvtst(0, 0);5796 gsym_addr(c, d);
5828 gsym_addr(c, d);
5829 } else
5830 vtop--;
5831 nocode_wanted = saved_nocode_wanted;5797 nocode_wanted = saved_nocode_wanted;
5832 skip(')');5798 skip(')');
5833 gsym(a);5799 gsym(a);
@@ -5852,21 +5818,19 @@ static void block(int *bsym, int *csym, int is_expr) · 18 unmodified lines
5852 a = gjmp(a); /* add implicit break */5818 a = gjmp(a); /* add implicit break */
5853 /* case lookup */5819 /* case lookup */
5854 gsym(b);5820 gsym(b);
5855 if (!nocode_wanted) {5821 qsort(sw.p, sw.n, sizeof(void*), case_cmp);
5856 qsort(sw.p, sw.n, sizeof(void*), case_cmp);5822 for (b = 1; b < sw.n; b++)
5857 for (b = 1; b < sw.n; b++)5823 if (sw.p[b - 1]->v2 >= sw.p[b]->v1)
5858 if (sw.p[b - 1]->v2 >= sw.p[b]->v1)5824 tcc_error("duplicate case value");
5859 tcc_error("duplicate case value");5825 /* Our switch table sorting is signed, so the compared
5860 /* Our switch table sorting is signed, so the compared5826 value needs to be as well when it's 64bit. */
5861 value needs to be as well when it's 64bit. */5827 if ((switchval.type.t & VT_BTYPE) == VT_LLONG)
5862 if ((switchval.type.t & VT_BTYPE) == VT_LLONG)5828 switchval.type.t &= ~VT_UNSIGNED;
5863 switchval.type.t &= ~VT_UNSIGNED;5829 vpushv(&switchval);
5864 vpushv(&switchval);5830 gcase(sw.p, sw.n, &a);
5865 gcase(sw.p, sw.n, &a);5831 vpop();
5866 vpop();5832 if (sw.def_sym)
5867 if (sw.def_sym)5833 gjmp_addr(sw.def_sym);
5868 gjmp_addr(sw.def_sym);
5869 }
5870 dynarray_reset(&sw.p, &sw.n);5834 dynarray_reset(&sw.p, &sw.n);
5871 cur_switch = saved;5835 cur_switch = saved;
5872 /* break label */5836 /* break label */
@@ -5910,10 +5874,7 @@ static void block(int *bsym, int *csym, int is_expr) · 37 unmodified lines
5910 gexpr();5874 gexpr();
5911 if ((vtop->type.t & VT_BTYPE) != VT_PTR)5875 if ((vtop->type.t & VT_BTYPE) != VT_PTR)
5912 expect("pointer");5876 expect("pointer");
5913 if (!nocode_wanted)5877 ggoto();
5914 ggoto();
5915 else
5916 vtop--;
5917 } else if (tok >= TOK_UIDENT) {5878 } else if (tok >= TOK_UIDENT) {
5918 s = label_find(tok);5879 s = label_find(tok);
5919 /* put forward definition if needed */5880 /* put forward definition if needed */
@@ -5924,9 +5885,7 @@ static void block(int *bsym, int *csym, int is_expr) · 4 unmodified lines
5924 s->r = LABEL_FORWARD;5885 s->r = LABEL_FORWARD;
5925 }5886 }
5926 vla_sp_restore_root();5887 vla_sp_restore_root();
5927 if (nocode_wanted)5888 if (s->r & LABEL_FORWARD)
5928 ;
5929 else if (s->r & LABEL_FORWARD)
5930 s->jnext = gjmp(s->jnext);5889 s->jnext = gjmp(s->jnext);
5931 else5890 else
5932 gjmp_addr(s->jnext);5891 gjmp_addr(s->jnext);
@@ -6893,6 +6852,7 @@ static void gen_function(Sym *sym) · 960 unmodified lines
6893 6852
6894 rsym = 0;6853 rsym = 0;
6895 block(NULL, NULL, 0);6854 block(NULL, NULL, 0);
6855 nocode_wanted = 0;
6896 gsym(rsym);6856 gsym(rsym);
6897 gfunc_epilog();6857 gfunc_epilog();
6898 cur_text_section->data_offset = ind;6858 cur_text_section->data_offset = ind;
x86_64-gen.c+18−16
@@ -145,6 +145,8 @@ static int func_ret_sub; · 144 unmodified lines
145ST_FUNC void g(int c)145ST_FUNC void g(int c)
146{146{
147 int ind1;147 int ind1;
148 if (nocode_wanted)
149 return;
148 ind1 = ind + 1;150 ind1 = ind + 1;
149 if (ind1 > cur_text_section->data_allocated)151 if (ind1 > cur_text_section->data_allocated)
150 section_realloc(cur_text_section, ind1);152 section_realloc(cur_text_section, ind1);
@@ -213,9 +215,6 @@ void gsym(int t) · 62 unmodified lines
213 gsym_addr(t, ind);215 gsym_addr(t, ind);
214}216}
215 217
216/* psym is used to put an instruction with a data field which is a
217 reference to a symbol. It is in fact the same as oad ! */
218#define psym oad
219 218
220static int is64_type(int t)219static int is64_type(int t)
221{220{
@@ -227,18 +226,18 @@ static int is64_type(int t) · 5 unmodified lines
227/* instruction + 4 bytes data. Return the address of the data */226/* instruction + 4 bytes data. Return the address of the data */
228ST_FUNC int oad(int c, int s)227ST_FUNC int oad(int c, int s)
229{228{
230 int ind1;229 int t;
231 230 if (nocode_wanted)
231 return s;
232 o(c);232 o(c);
233 ind1 = ind + 4;233 t = ind;
234 if (ind1 > cur_text_section->data_allocated)234 gen_le32(s);
235 section_realloc(cur_text_section, ind1);235 return t;
236 write32le(cur_text_section->data + ind, s);
237 s = ind;
238 ind = ind1;
239 return s;
240}236}
241 237
238/* generate jmp to a label */
239#define gjmp2(instr,lbl) oad(instr,lbl)
240
242ST_FUNC void gen_addr32(int r, Sym *sym, long c)241ST_FUNC void gen_addr32(int r, Sym *sym, long c)
243{242{
244 if (r & VT_SYM)243 if (r & VT_SYM)
@@ -1703,7 +1702,7 @@ void gfunc_epilog(void) · 1458 unmodified lines
1703/* generate a jump to a label */1702/* generate a jump to a label */
1704int gjmp(int t)1703int gjmp(int t)
1705{1704{
1706 return psym(0xe9, t);1705 return gjmp2(0xe9, t);
1707}1706}
1708 1707
1709/* generate a jump to a fixed address */1708/* generate a jump to a fixed address */
@@ -1749,7 +1748,10 @@ ST_FUNC void gtst_addr(int inv, int a) · 39 unmodified lines
1749ST_FUNC int gtst(int inv, int t)1748ST_FUNC int gtst(int inv, int t)
1750{1749{
1751 int v = vtop->r & VT_VALMASK;1750 int v = vtop->r & VT_VALMASK;
1752 if (v == VT_CMP) {1751
1752 if (nocode_wanted) {
1753 ;
1754 } else if (v == VT_CMP) {
1753 /* fast case : can jump directly since flags are set */1755 /* fast case : can jump directly since flags are set */
1754 if (vtop->c.i & 0x100)1756 if (vtop->c.i & 0x100)
1755 {1757 {
@@ -1766,11 +1768,11 @@ ST_FUNC int gtst(int inv, int t) · 10 unmodified lines
1766 else1768 else
1767 {1769 {
1768 g(0x0f);1770 g(0x0f);
1769 t = psym(0x8a, t); /* jp t */1771 t = gjmp2(0x8a, t); /* jp t */
1770 }1772 }
1771 }1773 }
1772 g(0x0f);1774 g(0x0f);
1773 t = psym((vtop->c.i - 16) ^ inv, t);1775 t = gjmp2((vtop->c.i - 16) ^ inv, t);
1774 } else if (v == VT_JMP || v == VT_JMPI) {1776 } else if (v == VT_JMP || v == VT_JMPI) {
1775 /* && or || optimization */1777 /* && or || optimization */
1776 if ((v & 1) == inv) {1778 if ((v & 1) == inv) {

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