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
214214 {
215215 /* this is a good place to start adding big-endian support*/
216216 int ind1;
217−
217+ if (nocode_wanted)
218+ return;
218219 ind1 = ind + 4;
219220 if (!cur_text_section)
220221 tcc_error("compiler error! This happens f.ex. if the compiler\n"
@@ -1411,6 +1412,8 @@ void gfunc_epilog(void) · 1190 unmodified lines
14111412 int gjmp(int t)
14121413 {
14131414 int r;
1415+ if (nocode_wanted)
1416+ return t;
14141417 r=ind;
14151418 o(0xE0000000|encbranch(r,t,1));
14161419 return r;
@@ -1427,9 +1430,13 @@ int gtst(int inv, int t) · 10 unmodified lines
14271430 {
14281431 int v, r;
14291432 uint32_t op;
1433+
14301434 v = vtop->r & VT_VALMASK;
14311435 r=ind;
1432− if (v == VT_CMP) {
1436+
1437+ if (nocode_wanted) {
1438+ ;
1439+ } else if (v == VT_CMP) {
14331440 op=mapcc(inv?negcc(vtop->c.i):vtop->c.i);
14341441 op|=encbranch(r,t,1);
14351442 o(op);
arm64-gen.c+4−0
@@ -95,6 +95,8 @@ static uint32_t fltr(int r) · 94 unmodified lines
9595 ST_FUNC void o(unsigned int c)
9696 {
9797 int ind1 = ind + 4;
98+ if (nocode_wanted)
99+ return;
98100 if (ind1 > cur_text_section->data_allocated)
99101 section_realloc(cur_text_section, ind1);
100102 write32le(cur_text_section->data + ind, c);
@@ -1278,6 +1280,8 @@ ST_FUNC void gfunc_epilog(void) · 1177 unmodified lines
12781280 ST_FUNC int gjmp(int t)
12791281 {
12801282 int r = ind;
1283+ if (nocode_wanted)
1284+ return t;
12811285 o(t);
12821286 return r;
12831287 }
c67-gen.c+7−2
@@ -182,7 +182,8 @@ FILE *f = NULL; · 181 unmodified lines
182182 void C67_g(int c)
183183 {
184184 int ind1;
185−
185+ if (nocode_wanted)
186+ return;
186187 #ifdef ASSEMBLY_LISTING_C67
187188 fprintf(f, " %08X", c);
188189 #endif
@@ -2038,6 +2039,8 @@ void gfunc_epilog(void) · 1849 unmodified lines
20382039 int gjmp(int t)
20392040 {
20402041 int ind1 = ind;
2042+ if (nocode_wanted)
2043+ return t;
20412044
20422045 C67_MVKL(C67_A0, t); //r=reg to load, constant
20432046 C67_MVKH(C67_A0, t); //r=reg to load, constant
@@ -2070,7 +2073,9 @@ int gtst(int inv, int t) · 26 unmodified lines
20702073 int v, *p;
20712074
20722075 v = vtop->r & VT_VALMASK;
2073− if (v == VT_CMP) {
2076+ if (nocode_wanted) {
2077+ ;
2078+ } else if (v == VT_CMP) {
20742079 /* fast case : can jump directly since flags are set */
20752080 // C67 uses B2 sort of as flags register
20762081 ind1 = ind;
i386-gen.c+15−18
@@ -70,8 +70,8 @@ enum { · 69 unmodified lines
7070 /* maximum alignment (for aligned attribute support) */
7171 #define MAX_ALIGN 8
7272
73−
74−#define psym oad
73+/* generate jmp to a label */
74+#define gjmp2(instr,lbl) oad(instr,lbl)
7575
7676 /******************************************************/
7777 #else /* ! TARGET_DEFS_ONLY */
@@ -100,6 +100,8 @@ static unsigned long func_bound_ind; · 22 unmodified lines
100100 ST_FUNC void g(int c)
101101 {
102102 int ind1;
103+ if (nocode_wanted)
104+ return;
103105 ind1 = ind + 1;
104106 if (ind1 > cur_text_section->data_allocated)
105107 section_realloc(cur_text_section, ind1);
@@ -145,23 +147,16 @@ ST_FUNC void gsym(int t) · 39 unmodified lines
145147 gsym_addr(t, ind);
146148 }
147149
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−
152150 /* instruction + 4 bytes data. Return the address of the data */
153151 ST_FUNC int oad(int c, int s)
154152 {
155− int ind1;
156−
153+ int t;
154+ if (nocode_wanted)
155+ return s;
157156 o(c);
158− ind1 = ind + 4;
159− if (ind1 > cur_text_section->data_allocated)
160− section_realloc(cur_text_section, ind1);
161− write32le(cur_text_section->data + ind, s);
162− s = ind;
163− ind = ind1;
164− return s;
157+ t = ind;
158+ gen_le32(s);
159+ return t;
165160 }
166161
167162 /* output constant with relocation if 'r & VT_SYM' is true */
@@ -676,7 +671,7 @@ ST_FUNC void gfunc_epilog(void) · 508 unmodified lines
676671 /* generate a jump to a label */
677672 ST_FUNC int gjmp(int t)
678673 {
679− return psym(0xe9, t);
674+ return gjmp2(0xe9, t);
680675 }
681676
682677 /* generate a jump to a fixed address */
@@ -722,10 +717,12 @@ ST_FUNC void gtst_addr(int inv, int a) · 39 unmodified lines
722717 ST_FUNC int gtst(int inv, int t)
723718 {
724719 int v = vtop->r & VT_VALMASK;
725− if (v == VT_CMP) {
720+ if (nocode_wanted) {
721+ ;
722+ } else if (v == VT_CMP) {
726723 /* fast case : can jump directly since flags are set */
727724 g(0x0f);
728− t = psym((vtop->c.i - 16) ^ inv, t);
725+ t = gjmp2((vtop->c.i - 16) ^ inv, t);
729726 } else if (v == VT_JMP || v == VT_JMPI) {
730727 /* && or || optimization */
731728 if ((v & 1) == inv) {
tccasm.c+6−1
@@ -915,8 +915,12 @@ static void asm_parse_directive(TCCState *s1) · 914 unmodified lines
915915 /* assemble a file */
916916 static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
917917 {
918+ int saved_nocode_wanted;
918919 int opcode;
919920
921+ saved_nocode_wanted = nocode_wanted;
922+ nocode_wanted = 0;
923+
920924 /* XXX: undefine C labels */
921925
922926 ch = file->buf_ptr[0];
@@ -960,7 +964,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 37 unmodified lines
960964 /* handle "extern void vide(void); __asm__("vide: ret");" as
961965 "__asm__("globl vide\nvide: ret");" */
962966 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) {
964968 sym = label_find(opcode);
965969 if (!sym) {
966970 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
989993
990994 asm_free_labels(s1);
991995
996+ nocode_wanted = saved_nocode_wanted;
992997 return 0;
993998 }
994999
tccgen.c+52−92
@@ -69,6 +69,7 @@ ST_DATA struct switch_t { · 68 unmodified lines
6969 } *cur_switch; /* current switch */
7070
7171 /* ------------------------------------------------------------------------- */
72+
7273 static void gen_cast(CType *type);
7374 static inline CType *pointed_type(CType *type);
7475 static 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
322323 addr_t addend)
323324 {
324325 int c = 0;
326+
327+ if (nocode_wanted && s == cur_text_section)
328+ return;
329+
325330 if (sym) {
326331 if (0 == sym->c)
327332 put_extern_sym(sym, NULL, 0, 0);
328333 c = sym->c;
329334 }
335+
330336 /* now we can add ELF relocation info */
331337 put_elf_reloca(symtab_section, s, offset, type, c, addend);
332338 }
@@ -774,6 +780,8 @@ ST_FUNC void save_reg_upstack(int r, int n) · 441 unmodified lines
774780
775781 if ((r &= VT_VALMASK) >= VT_CONST)
776782 return;
783+ if (nocode_wanted)
784+ return;
777785
778786 /* modify all stack values */
779787 saved = 0;
@@ -865,6 +873,8 @@ ST_FUNC int get_reg(int rc) · 85 unmodified lines
865873 /* find a free register */
866874 for(r=0;r<NB_REGS;r++) {
867875 if (reg_classes[r] & rc) {
876+ if (nocode_wanted)
877+ return r;
868878 for(p=vstack;p<=vtop;p++) {
869879 if ((p->r & VT_VALMASK) == r ||
870880 (p->r2 & VT_VALMASK) == r)
@@ -913,7 +923,7 @@ static void move_reg(int r, int s, int t) · 42 unmodified lines
913923 /* get address of vtop (vtop MUST BE an lvalue) */
914924 ST_FUNC void gaddrof(void)
915925 {
916− if (vtop->r & VT_REF && !nocode_wanted)
926+ if (vtop->r & VT_REF)
917927 gv(RC_INT);
918928 vtop->r &= ~VT_LVAL;
919929 /* tricky: if saved lvalue, then we can go back to lvalue */
@@ -1317,7 +1327,7 @@ ST_FUNC void vpop(void) · 397 unmodified lines
13171327 v = vtop->r & VT_VALMASK;
13181328 #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
13191329 /* for x86, we need to pop the FP stack */
1320− if (v == TREG_ST0 && !nocode_wanted) {
1330+ if (v == TREG_ST0) {
13211331 o(0xd8dd); /* fstp %st(0) */
13221332 } else
13231333 #endif
@@ -1607,7 +1617,7 @@ static void gen_opl(int op) · 283 unmodified lines
16071617 b = gvtst(0, 0);
16081618 } else {
16091619 #if defined(TCC_TARGET_I386)
1610− b = psym(0x850f, 0);
1620+ b = gjmp2(0x850f, 0);
16111621 #elif defined(TCC_TARGET_ARM)
16121622 b = ind;
16131623 o(0x1A000000 | encbranch(ind, 0, 1));
@@ -1789,23 +1799,12 @@ static void gen_opic(int op) · 175 unmodified lines
17891799 vtop->c.i = l2;
17901800 } else {
17911801 general_case:
1792− if (!nocode_wanted) {
17931802 /* call low level op generator */
17941803 if (t1 == VT_LLONG || t2 == VT_LLONG ||
17951804 (PTR_SIZE == 8 && (t1 == VT_PTR || t2 == VT_PTR)))
17961805 gen_opl(op);
17971806 else
17981807 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− }
18091808 }
18101809 }
18111810 }
@@ -1866,11 +1865,7 @@ static void gen_opif(int op) · 54 unmodified lines
18661865 vtop--;
18671866 } else {
18681867 general_case:
1869− if (!nocode_wanted) {
1870− gen_opf(op);
1871− } else {
1872− vtop--;
1873− }
1868+ gen_opf(op);
18741869 }
18751870 }
18761871
@@ -2149,7 +2144,7 @@ redo: · 272 unmodified lines
21492144 }
21502145 }
21512146 // Make sure that we have converted to an rvalue:
2152− if (vtop->r & VT_LVAL && !nocode_wanted)
2147+ if (vtop->r & VT_LVAL)
21532148 gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT);
21542149 }
21552150
@@ -2255,7 +2250,7 @@ static void gen_cast(CType *type) · 99 unmodified lines
22552250 }
22562251
22572252 /* bitfields first get cast to ints */
2258− if (vtop->type.t & VT_BITFIELD && !nocode_wanted) {
2253+ if (vtop->type.t & VT_BITFIELD) {
22592254 gv(RC_INT);
22602255 }
22612256
@@ -2331,7 +2326,7 @@ static void gen_cast(CType *type) · 69 unmodified lines
23312326 } else if (p && dbt == VT_BOOL) {
23322327 vtop->r = VT_CONST;
23332328 vtop->c.i = 1;
2334− } else if (!nocode_wanted) {
2329+ } else {
23352330 /* non constant case: generate code */
23362331 if (sf && df) {
23372332 /* convert from fp to fp */
@@ -2883,7 +2878,6 @@ ST_FUNC void vstore(void) · 545 unmodified lines
28832878 /* if structure, only generate pointer */
28842879 /* structure assignment : generate memcpy */
28852880 /* XXX: optimize if small size */
2886− if (!nocode_wanted) {
28872881 size = type_size(&vtop->type, &align);
28882882
28892883 /* destination */
@@ -2910,10 +2904,7 @@ ST_FUNC void vstore(void) · 20 unmodified lines
29102904 /* type size */
29112905 vpushi(size);
29122906 gfunc_call(3);
2913− } else {
2914− vswap();
2915− vpop();
2916− }
2907+
29172908 /* leave source on stack */
29182909 } else if (ft & VT_BITFIELD) {
29192910 /* bitfield store handling */
@@ -2961,7 +2952,6 @@ ST_FUNC void vstore(void) · 41 unmodified lines
29612952 vpop();
29622953
29632954 } else {
2964− if (!nocode_wanted) {
29652955 #ifdef CONFIG_TCC_BCHECK
29662956 /* bound check case */
29672957 if (vtop[-1].r & VT_MUSTBOUND) {
@@ -3020,7 +3010,7 @@ ST_FUNC void vstore(void) · 52 unmodified lines
30203010 } else {
30213011 store(r, vtop - 1);
30223012 }
3023− }
3013+
30243014 vswap();
30253015 vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
30263016 vtop->r |= delayed_cast;
@@ -3033,10 +3023,7 @@ ST_FUNC void inc(int post, int c) · 6 unmodified lines
30333023 test_lvalue();
30343024 vdup(); /* save lvalue */
30353025 if (post) {
3036− if (!nocode_wanted)
3037− gv_dup(); /* duplicate value */
3038− else
3039− vdup(); /* duplicate value */
3026+ gv_dup(); /* duplicate value */
30403027 vrotb(3);
30413028 vrotb(3);
30423029 }
@@ -4189,7 +4176,7 @@ ST_FUNC void indir(void) · 1146 unmodified lines
41894176 return;
41904177 expect("pointer");
41914178 }
4192− if ((vtop->r & VT_LVAL) && !nocode_wanted)
4179+ if (vtop->r & VT_LVAL)
41934180 gv(RC_INT);
41944181 vtop->type = *pointed_type(&vtop->type);
41954182 /* Arrays and functions are never lvalues */
@@ -4382,8 +4369,7 @@ ST_FUNC void unary(void) · 186 unmodified lines
43824369 if (const_wanted)
43834370 tcc_error("expected constant");
43844371 /* save all registers */
4385− if (!nocode_wanted)
4386− save_regs(0);
4372+ save_regs(0);
43874373 /* statement expression : we do not accept break/continue
43884374 inside as GCC does */
43894375 block(NULL, NULL, 1);
@@ -4610,8 +4596,6 @@ ST_FUNC void unary(void) · 220 unmodified lines
46104596
46114597 #ifdef TCC_TARGET_ARM64
46124598 case TOK___va_start: {
4613− if (nocode_wanted)
4614− tcc_error("statement in global scope");
46154599 next();
46164600 skip('(');
46174601 expr_eq();
@@ -4626,8 +4610,6 @@ ST_FUNC void unary(void) · 8 unmodified lines
46264610 }
46274611 case TOK___va_arg: {
46284612 CType type;
4629− if (nocode_wanted)
4630− tcc_error("statement in global scope");
46314613 next();
46324614 skip('(');
46334615 expr_eq();
@@ -4906,11 +4888,7 @@ ST_FUNC void unary(void) · 272 unmodified lines
49064888 if (sa)
49074889 tcc_error("too few arguments to function");
49084890 skip(')');
4909− if (!nocode_wanted) {
4910− gfunc_call(nb_args);
4911− } else {
4912− vtop -= (nb_args + 1);
4913− }
4891+ gfunc_call(nb_args);
49144892
49154893 /* return value */
49164894 for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {
@@ -5083,9 +5061,9 @@ static void expr_land(void) · 166 unmodified lines
50835061 expr_or();
50845062 vpop();
50855063 }
5064+ nocode_wanted = saved_nocode_wanted;
50865065 if (t)
50875066 gsym(t);
5088− nocode_wanted = saved_nocode_wanted;
50895067 gen_cast(&int_type);
50905068 break;
50915069 }
@@ -5127,9 +5105,9 @@ static void expr_lor(void) · 35 unmodified lines
51275105 expr_land();
51285106 vpop();
51295107 }
5108+ nocode_wanted = saved_nocode_wanted;
51305109 if (t)
51315110 gsym(t);
5132− nocode_wanted = saved_nocode_wanted;
51335111 gen_cast(&int_type);
51345112 break;
51355113 }
@@ -5206,16 +5184,6 @@ static void expr_cond(void) · 70 unmodified lines
52065184 }
52075185 }
52085186 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. */
52195187 if (vtop != vstack) {
52205188 /* needed to avoid having different registers saved in
52215189 each branch */
@@ -5575,19 +5543,22 @@ static void block(int *bsym, int *csym, int is_expr) · 353 unmodified lines
55755543 gexpr();
55765544 skip(')');
55775545 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)
55795551 nocode_wanted |= 2;
5580− a = gvtst(1, 0);
55815552 block(bsym, csym, 0);
55825553 if (cond != 1)
55835554 nocode_wanted = saved_nocode_wanted;
55845555 c = tok;
55855556 if (c == TOK_ELSE) {
55865557 next();
5587− if (cond == 1)
5588− nocode_wanted |= 2;
55895558 d = gjmp(0);
55905559 gsym(a);
5560+ if (cond == 1)
5561+ nocode_wanted |= 2;
55915562 block(bsym, csym, 0);
55925563 gsym(d); /* patch else jmp */
55935564 if (cond != 0)
@@ -5610,8 +5581,7 @@ static void block(int *bsym, int *csym, int is_expr) · 16 unmodified lines
56105581 block(&a, &b, 0);
56115582 nocode_wanted = saved_nocode_wanted;
56125583 --local_scope;
5613− if(!nocode_wanted)
5614− gjmp_addr(d);
5584+ gjmp_addr(d);
56155585 gsym(a);
56165586 gsym_addr(b, d);
56175587 } else if (tok == '{') {
@@ -5801,8 +5771,7 @@ static void block(int *bsym, int *csym, int is_expr) · 183 unmodified lines
58015771 saved_nocode_wanted = nocode_wanted;
58025772 block(&a, &b, 0);
58035773 nocode_wanted = saved_nocode_wanted;
5804− if(!nocode_wanted)
5805− gjmp_addr(c);
5774+ gjmp_addr(c);
58065775 gsym(a);
58075776 gsym_addr(b, c);
58085777 --local_scope;
@@ -5823,11 +5792,8 @@ static void block(int *bsym, int *csym, int is_expr) · 14 unmodified lines
58235792 skip('(');
58245793 gsym(b);
58255794 gexpr();
5826− if (!nocode_wanted) {
5827− c = gvtst(0, 0);
5828− gsym_addr(c, d);
5829− } else
5830− vtop--;
5795+ c = gvtst(0, 0);
5796+ gsym_addr(c, d);
58315797 nocode_wanted = saved_nocode_wanted;
58325798 skip(')');
58335799 gsym(a);
@@ -5852,21 +5818,19 @@ static void block(int *bsym, int *csym, int is_expr) · 18 unmodified lines
58525818 a = gjmp(a); /* add implicit break */
58535819 /* case lookup */
58545820 gsym(b);
5855− if (!nocode_wanted) {
5856− qsort(sw.p, sw.n, sizeof(void*), case_cmp);
5857− for (b = 1; b < sw.n; b++)
5858− if (sw.p[b - 1]->v2 >= sw.p[b]->v1)
5859− tcc_error("duplicate case value");
5860− /* Our switch table sorting is signed, so the compared
5861− value needs to be as well when it's 64bit. */
5862− if ((switchval.type.t & VT_BTYPE) == VT_LLONG)
5863− switchval.type.t &= ~VT_UNSIGNED;
5864− vpushv(&switchval);
5865− gcase(sw.p, sw.n, &a);
5866− vpop();
5867− if (sw.def_sym)
5868− gjmp_addr(sw.def_sym);
5869− }
5821+ qsort(sw.p, sw.n, sizeof(void*), case_cmp);
5822+ for (b = 1; b < sw.n; b++)
5823+ if (sw.p[b - 1]->v2 >= sw.p[b]->v1)
5824+ tcc_error("duplicate case value");
5825+ /* Our switch table sorting is signed, so the compared
5826+ value needs to be as well when it's 64bit. */
5827+ if ((switchval.type.t & VT_BTYPE) == VT_LLONG)
5828+ switchval.type.t &= ~VT_UNSIGNED;
5829+ vpushv(&switchval);
5830+ gcase(sw.p, sw.n, &a);
5831+ vpop();
5832+ if (sw.def_sym)
5833+ gjmp_addr(sw.def_sym);
58705834 dynarray_reset(&sw.p, &sw.n);
58715835 cur_switch = saved;
58725836 /* break label */
@@ -5910,10 +5874,7 @@ static void block(int *bsym, int *csym, int is_expr) · 37 unmodified lines
59105874 gexpr();
59115875 if ((vtop->type.t & VT_BTYPE) != VT_PTR)
59125876 expect("pointer");
5913− if (!nocode_wanted)
5914− ggoto();
5915− else
5916− vtop--;
5877+ ggoto();
59175878 } else if (tok >= TOK_UIDENT) {
59185879 s = label_find(tok);
59195880 /* put forward definition if needed */
@@ -5924,9 +5885,7 @@ static void block(int *bsym, int *csym, int is_expr) · 4 unmodified lines
59245885 s->r = LABEL_FORWARD;
59255886 }
59265887 vla_sp_restore_root();
5927− if (nocode_wanted)
5928− ;
5929− else if (s->r & LABEL_FORWARD)
5888+ if (s->r & LABEL_FORWARD)
59305889 s->jnext = gjmp(s->jnext);
59315890 else
59325891 gjmp_addr(s->jnext);
@@ -6893,6 +6852,7 @@ static void gen_function(Sym *sym) · 960 unmodified lines
68936852
68946853 rsym = 0;
68956854 block(NULL, NULL, 0);
6855+ nocode_wanted = 0;
68966856 gsym(rsym);
68976857 gfunc_epilog();
68986858 cur_text_section->data_offset = ind;
x86_64-gen.c+18−16
@@ -145,6 +145,8 @@ static int func_ret_sub; · 144 unmodified lines
145145 ST_FUNC void g(int c)
146146 {
147147 int ind1;
148+ if (nocode_wanted)
149+ return;
148150 ind1 = ind + 1;
149151 if (ind1 > cur_text_section->data_allocated)
150152 section_realloc(cur_text_section, ind1);
@@ -213,9 +215,6 @@ void gsym(int t) · 62 unmodified lines
213215 gsym_addr(t, ind);
214216 }
215217
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
219218
220219 static int is64_type(int t)
221220 {
@@ -227,18 +226,18 @@ static int is64_type(int t) · 5 unmodified lines
227226 /* instruction + 4 bytes data. Return the address of the data */
228227 ST_FUNC int oad(int c, int s)
229228 {
230− int ind1;
231−
229+ int t;
230+ if (nocode_wanted)
231+ return s;
232232 o(c);
233− ind1 = ind + 4;
234− if (ind1 > cur_text_section->data_allocated)
235− section_realloc(cur_text_section, ind1);
236− write32le(cur_text_section->data + ind, s);
237− s = ind;
238− ind = ind1;
239− return s;
233+ t = ind;
234+ gen_le32(s);
235+ return t;
240236 }
241237
238+/* generate jmp to a label */
239+#define gjmp2(instr,lbl) oad(instr,lbl)
240+
242241 ST_FUNC void gen_addr32(int r, Sym *sym, long c)
243242 {
244243 if (r & VT_SYM)
@@ -1703,7 +1702,7 @@ void gfunc_epilog(void) · 1458 unmodified lines
17031702 /* generate a jump to a label */
17041703 int gjmp(int t)
17051704 {
1706− return psym(0xe9, t);
1705+ return gjmp2(0xe9, t);
17071706 }
17081707
17091708 /* generate a jump to a fixed address */
@@ -1749,7 +1748,10 @@ ST_FUNC void gtst_addr(int inv, int a) · 39 unmodified lines
17491748 ST_FUNC int gtst(int inv, int t)
17501749 {
17511750 int v = vtop->r & VT_VALMASK;
1752− if (v == VT_CMP) {
1751+
1752+ if (nocode_wanted) {
1753+ ;
1754+ } else if (v == VT_CMP) {
17531755 /* fast case : can jump directly since flags are set */
17541756 if (vtop->c.i & 0x100)
17551757 {
@@ -1766,11 +1768,11 @@ ST_FUNC int gtst(int inv, int t) · 10 unmodified lines
17661768 else
17671769 {
17681770 g(0x0f);
1769− t = psym(0x8a, t); /* jp t */
1771+ t = gjmp2(0x8a, t); /* jp t */
17701772 }
17711773 }
17721774 g(0x0f);
1773− t = psym((vtop->c.i - 16) ^ inv, t);
1775+ t = gjmp2((vtop->c.i - 16) ^ inv, t);
17741776 } else if (v == VT_JMP || v == VT_JMPI) {
17751777 /* && or || optimization */
17761778 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