History

use register classes (will allow better and simpler code gen - fixed long double handling

bellard committed 24 years ago

Commit 21c35b91 parent 49855112 files · +183 −142Browse files

Unified · Split

2 files
  1. i386-gen.c +103 −109
  2. tcc.c +80 −33
i386-gen.c+103−109
@@ -21,11 +21,11 @@ · 20 unmodified lines
21/* number of available registers */21/* number of available registers */
22#define NB_REGS 422#define NB_REGS 4
23 23
24#define NB_REG_CLASSES 2
25
26/* a register can belong to several classes */24/* a register can belong to several classes */
27#define REG_CLASS_INT 0x000125#define RC_INT 0x0001 /* generic integer register */
28#define REG_CLASS_FLOAT 0x000226#define RC_FLOAT 0x0002 /* generic float register */
27#define RC_IRET 0x0004 /* function returned integer register */
28#define RC_FRET 0x0008 /* function returned float register */
29 29
30/* pretty names for the registers */30/* pretty names for the registers */
31enum {31enum {
@@ -36,16 +36,15 @@ enum { · 4 unmodified lines
36};36};
37 37
38int reg_classes[NB_REGS] = {38int reg_classes[NB_REGS] = {
39 REG_CLASS_INT, /* eax */39 /* eax */ RC_INT | RC_IRET,
40 REG_CLASS_INT, /* ecx */40 /* ecx */ RC_INT,
41 REG_CLASS_INT, /* edx */41 /* edx */ RC_INT,
42 REG_CLASS_FLOAT, /* st0 */42 /* st0 */ RC_FLOAT | RC_FRET,
43};43};
44 44
45/* integer return register for functions */45/* return registers for function */
46#define FUNC_RET_REG 0 46#define REG_IRET REG_EAX
47/* float return register for functions */47#define REG_FRET REG_ST0
48#define FUNC_RET_FREG 3
49 48
50/* defined if function parameters must be evaluated in reverse order */49/* defined if function parameters must be evaluated in reverse order */
51#define INVERT_FUNC_PARAMS50#define INVERT_FUNC_PARAMS
@@ -89,40 +88,17 @@ void gen_le32(int c) · 37 unmodified lines
89 g(c >> 24);88 g(c >> 24);
90}89}
91 90
92/* add a new relocation entry to symbol 's' */91/* patch relocation entry with value 'val' */
93void greloc(Sym *s, int addr, int type)92void greloc_patch1(Reloc *p, int val)
94{
95 Reloc *p;
96 p = malloc(sizeof(Reloc));
97 if (!p)
98 error("memory full");
99 p->type = type;
100 p->addr = addr;
101 p->next = (Reloc *)s->c;
102 s->c = (int)p;
103}
104
105/* patch each relocation entry with value 'val' */
106void greloc_patch(Sym *s, int val)
107{93{
108 Reloc *p, *p1;94 switch(p->type) {
109 95 case RELOC_ADDR32:
110 p = (Reloc *)s->c;96 *(int *)p->addr = val;
111 while (p != NULL) {97 break;
112 p1 = p->next;98 case RELOC_REL32:
113 switch(p->type) {99 *(int *)p->addr = val - p->addr - 4;
114 case RELOC_ADDR32:100 break;
115 *(int *)p->addr = val;
116 break;
117 case RELOC_REL32:
118 *(int *)p->addr = val - p->addr - 4;
119 break;
120 }
121 free(p);
122 p = p1;
123 }101 }
124 s->c = val;
125 s->r &= ~VT_FORWARD;
126}102}
127 103
128/* output a symbol and patch all calls to it */104/* output a symbol and patch all calls to it */
@@ -166,6 +142,30 @@ void gen_addr32(int r, int c) · 37 unmodified lines
166 }142 }
167}143}
168 144
145/* generate a modrm reference. 'op_reg' contains the addtionnal 3
146 opcode bits */
147void gen_modrm(int op_reg, int r, int c)
148{
149 op_reg = op_reg << 3;
150 if ((r & VT_VALMASK) == VT_CONST) {
151 /* constant memory reference */
152 o(0x05 | op_reg);
153 gen_addr32(r, c);
154 } else if ((r & VT_VALMASK) == VT_LOCAL) {
155 /* currently, we use only ebp as base */
156 if (c == (char)c) {
157 /* short reference */
158 o(0x45 | op_reg);
159 g(c);
160 } else {
161 oad(0x85 | op_reg, c);
162 }
163 } else {
164 g(0x00 | op_reg | (r & VT_VALMASK));
165 }
166}
167
168
169/* load 'r' from value 'sv' */169/* load 'r' from value 'sv' */
170void load(int r, SValue *sv)170void load(int r, SValue *sv)
171{171{
@@ -183,7 +183,7 @@ void load(int r, SValue *sv) · 11 unmodified lines
183 v1.r = VT_LOCAL | VT_LVAL;183 v1.r = VT_LOCAL | VT_LVAL;
184 v1.c.ul = fc;184 v1.c.ul = fc;
185 load(r, &v1);185 load(r, &v1);
186 v = r;186 fr = r;
187 }187 }
188 if ((ft & VT_BTYPE) == VT_FLOAT) {188 if ((ft & VT_BTYPE) == VT_FLOAT) {
189 o(0xd9); /* flds */189 o(0xd9); /* flds */
@@ -204,22 +204,14 @@ void load(int r, SValue *sv) · 14 unmodified lines
204 o(0xb70f); /* movzwl */204 o(0xb70f); /* movzwl */
205 else205 else
206 o(0x8b); /* movl */206 o(0x8b); /* movl */
207 207 gen_modrm(r, fr, fc);
208 if (v == VT_CONST) {
209 o(0x05 + r * 8); /* 0xXX, r */
210 gen_addr32(fr, fc);
211 } else if (v == VT_LOCAL) {
212 oad(0x85 + r * 8, fc); /* xx(%ebp), r */
213 } else {
214 g(0x00 + r * 8 + v); /* (v), r */
215 }
216 } else {208 } else {
217 if (v == VT_CONST) {209 if (v == VT_CONST) {
218 o(0xb8 + r); /* mov $xx, r */210 o(0xb8 + r); /* mov $xx, r */
219 gen_addr32(fr, fc);211 gen_addr32(fr, fc);
220 } else if (v == VT_LOCAL) {212 } else if (v == VT_LOCAL) {
221 o(0x8d);213 o(0x8d); /* lea xxx(%ebp), r */
222 oad(0x85 + r * 8, fc); /* lea xxx(%ebp), r */214 gen_modrm(r, VT_LOCAL, fc);
223 } else if (v == VT_CMP) {215 } else if (v == VT_CMP) {
224 oad(0xb8 + r, 0); /* mov $0, r */216 oad(0xb8 + r, 0); /* mov $0, r */
225 o(0x0f); /* setxx %br */217 o(0x0f); /* setxx %br */
@@ -247,8 +239,7 @@ void store(int r, SValue *v) · 21 unmodified lines
247 fc = v->c.ul;239 fc = v->c.ul;
248 fr = v->r & VT_VALMASK;240 fr = v->r & VT_VALMASK;
249 bt = ft & VT_BTYPE;241 bt = ft & VT_BTYPE;
250 /* XXX: incorrect if reg to reg */242 /* XXX: incorrect if float reg to reg */
251 /* XXX: should not flush float stack */
252 if (bt == VT_FLOAT) {243 if (bt == VT_FLOAT) {
253 o(0xd9); /* fsts */244 o(0xd9); /* fsts */
254 r = 2;245 r = 2;
@@ -267,13 +258,10 @@ void store(int r, SValue *v) · 12 unmodified lines
267 else258 else
268 o(0x89);259 o(0x89);
269 }260 }
270 if (fr == VT_CONST) {261 if (fr == VT_CONST ||
271 o(0x05 + r * 8); /* mov r,xxx */262 fr == VT_LOCAL ||
272 gen_addr32(v->r, fc);263 (v->r & VT_LVAL)) {
273 } else if (fr == VT_LOCAL) {264 gen_modrm(r, v->r, fc);
274 oad(0x85 + r * 8, fc); /* mov r,xxx(%ebp) */
275 } else if (v->r & VT_LVAL) {
276 g(fr + r * 8); /* mov r, (fr) */
277 } else if (fr != r) {265 } else if (fr != r) {
278 o(0xc0 + fr + r * 8); /* mov r, fr */266 o(0xc0 + fr + r * 8); /* mov r, fr */
279 }267 }
@@ -298,7 +286,7 @@ void gfunc_param(GFuncContext *c) · 18 unmodified lines
298 /* allocate the necessary size on stack */286 /* allocate the necessary size on stack */
299 oad(0xec81, size); /* sub $xxx, %esp */287 oad(0xec81, size); /* sub $xxx, %esp */
300 /* generate structure store */288 /* generate structure store */
301 r = get_reg(REG_CLASS_INT);289 r = get_reg(RC_INT);
302 o(0x89); /* mov %esp, r */290 o(0x89); /* mov %esp, r */
303 o(0xe0 + r);291 o(0xe0 + r);
304 vset(VT_INT, r, 0);292 vset(VT_INT, r, 0);
@@ -306,7 +294,7 @@ void gfunc_param(GFuncContext *c) · 1 unmodified line
306 vstore();294 vstore();
307 c->args_size += size;295 c->args_size += size;
308 } else if (is_float(vtop->t)) {296 } else if (is_float(vtop->t)) {
309 gv(); /* only one float register */297 gv(RC_FLOAT); /* only one float register */
310 if ((vtop->t & VT_BTYPE) == VT_FLOAT)298 if ((vtop->t & VT_BTYPE) == VT_FLOAT)
311 size = 4;299 size = 4;
312 else if ((vtop->t & VT_BTYPE) == VT_DOUBLE)300 else if ((vtop->t & VT_BTYPE) == VT_DOUBLE)
@@ -324,7 +312,7 @@ void gfunc_param(GFuncContext *c) · 11 unmodified lines
324 } else {312 } else {
325 /* simple type (currently always same size) */313 /* simple type (currently always same size) */
326 /* XXX: implicit cast ? */314 /* XXX: implicit cast ? */
327 r = gv();315 r = gv(RC_INT);
328 o(0x50 + r); /* push r */316 o(0x50 + r); /* push r */
329 c->args_size += 4;317 c->args_size += 4;
330 }318 }
@@ -347,7 +335,7 @@ void gfunc_call(GFuncContext *c) · 16 unmodified lines
347 }335 }
348 } else {336 } else {
349 /* otherwise, indirect call */337 /* otherwise, indirect call */
350 r = gv();338 r = gv(RC_INT);
351 o(0xff); /* call *r */339 o(0xff); /* call *r */
352 o(0xd0 + r);340 o(0xd0 + r);
353 }341 }
@@ -383,17 +371,22 @@ int gtst(int inv, int t) · 29 unmodified lines
383 t = gjmp(t);371 t = gjmp(t);
384 gsym(vtop->c.i);372 gsym(vtop->c.i);
385 }373 }
386 } else if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
387 /* constant jmp optimization */
388 if ((vtop->c.i != 0) != inv)
389 t = gjmp(t);
390 } else {374 } else {
391 /* XXX: floats */375 if (is_float(vtop->t)) {
392 v = gv();376 vpushi(0);
393 o(0x85);377 gen_op(TOK_NE);
394 o(0xc0 + v * 9);378 }
395 g(0x0f);379 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST) {
396 t = psym(0x85 ^ inv, t);380 /* constant jmp optimization */
381 if ((vtop->c.i != 0) != inv)
382 t = gjmp(t);
383 } else {
384 v = gv(RC_INT);
385 o(0x85);
386 o(0xc0 + v * 9);
387 g(0x0f);
388 t = psym(0x85 ^ inv, t);
389 }
397 }390 }
398 vtop--;391 vtop--;
399 return t;392 return t;
@@ -405,9 +398,9 @@ void gen_opi(int op) · 5 unmodified lines
405 int t, r, fr;398 int t, r, fr;
406 399
407 vswap();400 vswap();
408 r = gv();401 r = gv(RC_INT);
409 vswap();402 vswap();
410 fr = gv();403 fr = gv(RC_INT);
411 vtop--;404 vtop--;
412 405
413 if (op == '+') {406 if (op == '+') {
@@ -460,9 +453,9 @@ void gen_opi(int op) · 46 unmodified lines
460 oad(0xbd, t);453 oad(0xbd, t);
461 }454 }
462 if (op == '%' | op == TOK_UMOD)455 if (op == '%' | op == TOK_UMOD)
463 r = 2;456 r = REG_EDX;
464 else457 else
465 r = 0;458 r = REG_EAX;
466 vtop->r = r;459 vtop->r = r;
467 } else {460 } else {
468 vtop--;461 vtop--;
@@ -477,22 +470,22 @@ void gen_opi(int op) · 8 unmodified lines
477/* NOTE: currently floats can only be lvalues */470/* NOTE: currently floats can only be lvalues */
478void gen_opf(int op)471void gen_opf(int op)
479{472{
480 int a, ft, fc, swapped, r;473 int a, ft, fc, swapped;
481 474
482 /* convert constants to memory references */475 /* convert constants to memory references */
483 if ((vtop[-1].r & (VT_CONST | VT_LVAL)) == VT_CONST) {476 if ((vtop[-1].r & (VT_CONST | VT_LVAL)) == VT_CONST) {
484 vswap();477 vswap();
485 gv();478 gv(RC_FLOAT);
486 vswap();479 vswap();
487 }480 }
488 if ((vtop[0].r & (VT_CONST | VT_LVAL)) == VT_CONST)481 if ((vtop[0].r & (VT_CONST | VT_LVAL)) == VT_CONST)
489 gv();482 gv(RC_FLOAT);
490 483
491 /* must put at least one value in the floating point register */484 /* must put at least one value in the floating point register */
492 if ((vtop[-1].r & VT_LVAL) &&485 if ((vtop[-1].r & VT_LVAL) &&
493 (vtop[0].r & VT_LVAL)) {486 (vtop[0].r & VT_LVAL)) {
494 vswap();487 vswap();
495 gv();488 gv(RC_FLOAT);
496 vswap();489 vswap();
497 }490 }
498 if (op >= TOK_EQ && op <= TOK_GT) {491 if (op >= TOK_EQ && op <= TOK_GT) {
@@ -520,13 +513,18 @@ void gen_opf(int op) · 21 unmodified lines
520 vtop->r = VT_CMP;513 vtop->r = VT_CMP;
521 vtop->c.i = op;514 vtop->c.i = op;
522 } else {515 } else {
516 swapped = 0;
523 /* swap the stack if needed so that t1 is the register and t2 is517 /* swap the stack if needed so that t1 is the register and t2 is
524 the memory reference */518 the memory reference */
525 swapped = 0;
526 if (vtop[-1].r & VT_LVAL) {519 if (vtop[-1].r & VT_LVAL) {
527 vswap();520 vswap();
528 swapped = 1;521 swapped = 1;
529 }522 }
523 /* no memory reference possible for long double operations */
524 if ((vtop->t & VT_BTYPE) == VT_LDOUBLE) {
525 load(REG_ST0, vtop);
526 swapped = !swapped;
527 }
530 528
531 switch(op) {529 switch(op) {
532 default:530 default:
@@ -534,34 +532,30 @@ void gen_opf(int op) · 1 unmodified line
534 a = 0;532 a = 0;
535 break;533 break;
536 case '-':534 case '-':
537 a = 0x20;535 a = 4;
538 if (swapped)536 if (swapped)
539 a += 8;537 a++;
540 break;538 break;
541 case '*':539 case '*':
542 a = 0x08;540 a = 1;
543 break;541 break;
544 case '/':542 case '/':
545 a = 0x30;543 a = 6;
546 if (swapped)544 if (swapped)
547 a += 8;545 a++;
548 break;546 break;
549 }547 }
550 ft = vtop->t;548 ft = vtop->t;
551 fc = vtop->c.ul;549 fc = vtop->c.ul;
552 if ((ft & VT_BTYPE) == VT_DOUBLE)550 if ((ft & VT_BTYPE) == VT_LDOUBLE) {
553 o(0xdc);551 o(0xde); /* fxxxp %st, %st(1) */
554 else552 o(0xc1 + (a << 3));
555 o(0xd8);
556
557 r = vtop->r & VT_VALMASK;
558 if (r == VT_CONST) {
559 o(0x05 + a);
560 gen_addr32(vtop->r, fc);
561 } else if (r == VT_LOCAL) {
562 oad(0x85 + a, fc);
563 } else {553 } else {
564 g(0x00 + a + r);554 if ((ft & VT_BTYPE) == VT_DOUBLE)
555 o(0xdc);
556 else
557 o(0xd8);
558 gen_modrm(a, vtop->r, fc);
565 }559 }
566 vtop--;560 vtop--;
567 }561 }
@@ -570,7 +564,7 @@ void gen_opf(int op) · 2 unmodified lines
570/* convert integers to fp 't' type */564/* convert integers to fp 't' type */
571void gen_cvt_itof(int t)565void gen_cvt_itof(int t)
572{566{
573 gv();567 gv(RC_INT);
574 if ((vtop->t & (VT_BTYPE | VT_UNSIGNED)) == (VT_INT | VT_UNSIGNED)) {568 if ((vtop->t & (VT_BTYPE | VT_UNSIGNED)) == (VT_INT | VT_UNSIGNED)) {
575 /* unsigned int to float/double/long double */569 /* unsigned int to float/double/long double */
576 o(0x6a); /* push $0 */570 o(0x6a); /* push $0 */
@@ -599,7 +593,7 @@ void gen_cvt_ftoi(int t) · 22 unmodified lines
599{593{
600 int r, size;594 int r, size;
601 595
602 gv();596 gv(RC_FLOAT);
603 if (t == VT_INT | VT_UNSIGNED &&597 if (t == VT_INT | VT_UNSIGNED &&
604 t == VT_LLONG | VT_UNSIGNED &&598 t == VT_LLONG | VT_UNSIGNED &&
605 t == VT_LLONG)599 t == VT_LLONG)
@@ -607,7 +601,7 @@ void gen_cvt_ftoi(int t) · 1 unmodified line
607 else 601 else
608 size = 4;602 size = 4;
609 603
610 r = get_reg(REG_CLASS_INT);604 r = get_reg(RC_INT);
611 oad(0x2dd9, (int)&__tcc_int_fpu_control); /* ldcw xxx */605 oad(0x2dd9, (int)&__tcc_int_fpu_control); /* ldcw xxx */
612 oad(0xec81, size); /* sub $xxx, %esp */606 oad(0xec81, size); /* sub $xxx, %esp */
613 if (size == 4)607 if (size == 4)
@@ -626,7 +620,7 @@ void gen_cvt_ftoi(int t) · 12 unmodified lines
626void gen_cvt_ftof(int t)620void gen_cvt_ftof(int t)
627{621{
628 /* all we have to do on i386 is to put the float in a register */622 /* all we have to do on i386 is to put the float in a register */
629 gv();623 gv(RC_FLOAT);
630}624}
631 625
632/* pop stack value */626/* pop stack value */
tcc.c+80−33
@@ -340,7 +340,7 @@ void gexpr(void); · 339 unmodified lines
340void decl(int l);340void decl(int l);
341void decl_initializer(int t, int r, int c, int first, int size_only);341void decl_initializer(int t, int r, int c, int first, int size_only);
342int decl_initializer_alloc(int t, int sec, int has_init);342int decl_initializer_alloc(int t, int sec, int has_init);
343int gv(void);343int gv(int rc);
344void move_reg(int r, int s);344void move_reg(int r, int s);
345void save_reg(int r);345void save_reg(int r);
346void vpop(void);346void vpop(void);
@@ -360,7 +360,9 @@ int pointed_size(int t); · 13 unmodified lines
360int parse_btype(int *type_ptr);360int parse_btype(int *type_ptr);
361int type_decl(int *v, int t, int td);361int type_decl(int *v, int t, int td);
362void error(const char *fmt, ...);362void error(const char *fmt, ...);
363void vpushi(int v);
363void vset(int t, int r, int v);364void vset(int t, int r, int v);
365void greloc(Sym *s, int addr, int type);
364 366
365/* true if float/double/long double type */367/* true if float/double/long double type */
366static inline int is_float(int t)368static inline int is_float(int t)
@@ -419,6 +421,36 @@ void *dlsym(void *handle, char *symbol) · 52 unmodified lines
419 421
420#endif422#endif
421 423
424/* add a new relocation entry to symbol 's' */
425void greloc(Sym *s, int addr, int type)
426{
427 Reloc *p;
428 p = malloc(sizeof(Reloc));
429 if (!p)
430 error("memory full");
431 p->type = type;
432 p->addr = addr;
433 p->next = (Reloc *)s->c;
434 s->c = (int)p;
435}
436
437/* patch each relocation entry with value 'val' */
438void greloc_patch(Sym *s, int val)
439{
440 Reloc *p, *p1;
441
442 p = (Reloc *)s->c;
443 while (p != NULL) {
444 p1 = p->next;
445 greloc_patch1(p, val);
446 free(p);
447 p = p1;
448 }
449 s->c = val;
450 s->r &= ~VT_FORWARD;
451}
452
453
422static inline int isid(int c)454static inline int isid(int c)
423{455{
424 return (c >= 'a' && c <= 'z') ||456 return (c >= 'a' && c <= 'z') ||
@@ -1884,7 +1916,7 @@ void vsetc(int t, int r, CValue *vc) · 1459 unmodified lines
1884 /* cannot let cpu flags if other instruction are generated */1916 /* cannot let cpu flags if other instruction are generated */
1885 /* XXX: VT_JMP test too ? */1917 /* XXX: VT_JMP test too ? */
1886 if ((vtop->r & VT_VALMASK) == VT_CMP)1918 if ((vtop->r & VT_VALMASK) == VT_CMP)
1887 gv();1919 gv(RC_INT);
1888 vtop++;1920 vtop++;
1889 vtop->t = t;1921 vtop->t = t;
1890 vtop->r = r;1922 vtop->r = r;
@@ -2028,12 +2060,12 @@ void move_reg(int r, int s) · 137 unmodified lines
2028 }2060 }
2029}2061}
2030 2062
2031/* convert a (vtop->t, vtop->c) in register. lvalues are converted as2063/* store vtop a register belonging to class 'rc'. lvalues are
2032 values. Cannot be used if cannot be converted to register value2064 converted as values. Cannot be used if cannot be converted to
2033 (such as structures). */2065 register value (such as structures). */
2034int gv(void)2066int gv(int rc)
2035{2067{
2036 int r, bit_pos, bit_size, rc, size, align, i;2068 int r, bit_pos, bit_size, size, align, i;
2037 2069
2038 /* NOTE: get_reg can modify vstack[] */2070 /* NOTE: get_reg can modify vstack[] */
2039 if (vtop->t & VT_BITFIELD) {2071 if (vtop->t & VT_BITFIELD) {
@@ -2047,7 +2079,7 @@ int gv(void) · 7 unmodified lines
2047 vpushi(32 - bit_size);2079 vpushi(32 - bit_size);
2048 /* NOTE: transformed to SHR if unsigned */2080 /* NOTE: transformed to SHR if unsigned */
2049 gen_op(TOK_SAR);2081 gen_op(TOK_SAR);
2050 r = gv();2082 r = gv(rc);
2051 } else {2083 } else {
2052 if (is_float(vtop->t) && 2084 if (is_float(vtop->t) &&
2053 (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {2085 (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
@@ -2064,14 +2096,16 @@ int gv(void) · 10 unmodified lines
2064 glo += size << 2;2096 glo += size << 2;
2065 }2097 }
2066 r = vtop->r & VT_VALMASK;2098 r = vtop->r & VT_VALMASK;
2067 if (r >= VT_CONST || (vtop->r & VT_LVAL)) {2099 /* need to reload if:
2068 if (is_float(vtop->t))2100 - constant
2069 rc = REG_CLASS_FLOAT;2101 - lvalue (need to dereference pointer)
2070 else2102 - already a register, but not in the right class */
2071 rc = REG_CLASS_INT;2103 if (r >= VT_CONST ||
2104 (vtop->r & VT_LVAL) ||
2105 !(reg_classes[r] & rc)) {
2072 r = get_reg(rc);2106 r = get_reg(rc);
2107 load(r, vtop);
2073 }2108 }
2074 load(r, vtop);
2075 vtop->r = r;2109 vtop->r = r;
2076 }2110 }
2077 return r;2111 return r;
@@ -2620,7 +2654,7 @@ void gen_assign_cast(int dt) · 542 unmodified lines
2620/* store vtop in lvalue pushed on stack */2654/* store vtop in lvalue pushed on stack */
2621void vstore(void)2655void vstore(void)
2622{2656{
2623 int ft, r, t, size, align, bit_size, bit_pos;2657 int ft, r, t, size, align, bit_size, bit_pos, rc;
2624 GFuncContext gf;2658 GFuncContext gf;
2625 2659
2626 ft = vtop[-1].t;2660 ft = vtop[-1].t;
@@ -2675,11 +2709,14 @@ void vstore(void) · 48 unmodified lines
2675 /* store result */2709 /* store result */
2676 vstore();2710 vstore();
2677 } else {2711 } else {
2678 r = gv(); /* generate value */2712 rc = RC_INT;
2713 if (is_float(ft))
2714 rc = RC_FLOAT;
2715 r = gv(rc); /* generate value (XXX: move that to store code) */
2679 /* if lvalue was saved on stack, must read it */2716 /* if lvalue was saved on stack, must read it */
2680 if ((vtop[-1].r & VT_VALMASK) == VT_LLOCAL) {2717 if ((vtop[-1].r & VT_VALMASK) == VT_LLOCAL) {
2681 SValue sv;2718 SValue sv;
2682 t = get_reg(REG_CLASS_INT);2719 t = get_reg(RC_INT);
2683 sv.t = VT_INT;2720 sv.t = VT_INT;
2684 sv.r = VT_LOCAL | VT_LVAL;2721 sv.r = VT_LOCAL | VT_LVAL;
2685 sv.c.ul = vtop[-1].c.ul;2722 sv.c.ul = vtop[-1].c.ul;
@@ -2696,19 +2733,24 @@ void vstore(void) · 10 unmodified lines
2696/* post defines POST/PRE add. c is the token ++ or -- */2733/* post defines POST/PRE add. c is the token ++ or -- */
2697void inc(int post, int c)2734void inc(int post, int c)
2698{2735{
2699 int r, r1;2736 int r, r1, rc, t;
2700 SValue sv;2737 SValue sv;
2701 2738
2702 test_lvalue();2739 test_lvalue();
2703 if (post)2740 if (post)
2704 vdup(); /* room for returned value */2741 vdup(); /* room for returned value */
2705 vdup(); /* save lvalue */2742 vdup(); /* save lvalue */
2706 r = gv();
2707 if (post) {2743 if (post) {
2708 /* duplicate value */2744 /* duplicate value */
2709 /* XXX: handle floats */2745 rc = RC_INT;
2710 r1 = get_reg(REG_CLASS_INT);
2711 sv.t = VT_INT;2746 sv.t = VT_INT;
2747 t = vtop->t & VT_TYPE;
2748 if (is_float(t)) {
2749 rc = RC_FLOAT;
2750 sv.t = t;
2751 }
2752 r = gv(rc);
2753 r1 = get_reg(rc);
2712 sv.r = r;2754 sv.r = r;
2713 sv.c.ul = 0;2755 sv.c.ul = 0;
2714 load(r1, &sv); /* move r to r1 */2756 load(r1, &sv); /* move r to r1 */
@@ -3137,10 +3179,10 @@ Sym *external_sym(int v, int u, int r) · 422 unmodified lines
3137 3179
3138void indir(void)3180void indir(void)
3139{3181{
3140 if (vtop->r & VT_LVAL)
3141 gv();
3142 if ((vtop->t & VT_BTYPE) != VT_PTR)3182 if ((vtop->t & VT_BTYPE) != VT_PTR)
3143 expect("pointer");3183 expect("pointer");
3184 if (vtop->r & VT_LVAL)
3185 gv(RC_INT);
3144 vtop->t = pointed_type(vtop->t);3186 vtop->t = pointed_type(vtop->t);
3145 if (!(vtop->t & VT_ARRAY)) /* an array is never an lvalue */3187 if (!(vtop->t & VT_ARRAY)) /* an array is never an lvalue */
3146 vtop->r |= VT_LVAL;3188 vtop->r |= VT_LVAL;
@@ -3442,7 +3484,11 @@ void unary(void) · 295 unmodified lines
3442 gfunc_param(&gf);3484 gfunc_param(&gf);
3443 } else {3485 } else {
3444 ret.t = s->t; 3486 ret.t = s->t;
3445 ret.r = FUNC_RET_REG; /* return in register */3487 /* return in register */
3488 if (is_float(ret.t))
3489 ret.r = REG_FRET;
3490 else
3491 ret.r = REG_IRET;
3446 ret.c.i = 0;3492 ret.c.i = 0;
3447 }3493 }
3448#ifndef INVERT_FUNC_PARAMS3494#ifndef INVERT_FUNC_PARAMS
@@ -3561,7 +3607,7 @@ void eor(void) · 112 unmodified lines
3561/* XXX: better constant handling */3607/* XXX: better constant handling */
3562void expr_eq(void)3608void expr_eq(void)
3563{3609{
3564 int t, u, c, r1, r2;3610 int t, u, c, r1, r2, rc;
3565 3611
3566 if (const_wanted) {3612 if (const_wanted) {
3567 sum(10);3613 sum(10);
@@ -3582,16 +3628,19 @@ void expr_eq(void) · 14 unmodified lines
3582 if (tok == '?') {3628 if (tok == '?') {
3583 next();3629 next();
3584 t = gtst(1, 0);3630 t = gtst(1, 0);
3585
3586 gexpr();3631 gexpr();
3587 r1 = gv();3632 /* XXX: float handling ? */
3633 rc = RC_INT;
3634 if (is_float(vtop->t))
3635 rc = RC_FLOAT;
3636 r1 = gv(rc);
3588 vpop();3637 vpop();
3589 skip(':');3638 skip(':');
3590 u = gjmp(0);3639 u = gjmp(0);
3591 3640
3592 gsym(t);3641 gsym(t);
3593 expr_eq();3642 expr_eq();
3594 r2 = gv();3643 r2 = gv(rc);
3595 move_reg(r1, r2);3644 move_reg(r1, r2);
3596 vtop->r = r1;3645 vtop->r = r1;
3597 gsym(u);3646 gsym(u);
@@ -3718,11 +3767,9 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 120 unmodified lines
3718 /* copy structure value to pointer */3767 /* copy structure value to pointer */
3719 vstore();3768 vstore();
3720 } else if (is_float(func_vt)) {3769 } else if (is_float(func_vt)) {
3721 /* move return value to float return register */3770 gv(RC_FRET);
3722 move_reg(FUNC_RET_FREG, gv());
3723 } else {3771 } else {
3724 /* move return value to standard return register */3772 gv(RC_IRET);
3725 move_reg(FUNC_RET_REG, gv());
3726 }3773 }
3727 vpop();3774 vpop();
3728 }3775 }
@@ -3794,7 +3841,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 65 unmodified lines
3794 next();3841 next();
3795 skip('(');3842 skip('(');
3796 gexpr();3843 gexpr();
3797 case_reg = gv();3844 case_reg = gv(RC_INT);
3798 vpop();3845 vpop();
3799 skip(')');3846 skip(')');
3800 a = 0;3847 a = 0;

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