History

mark apple targets with a boolean

It is more natural to branch on a flag than have different function pointers for high-level passes.

Quentin Carbonneaux committed 4 years ago

Commit b03a8971 parent a7e16028 files · +41 −86Browse files

Unified · Split

8 files
  1. all.h +1 −0
  2. amd64/all.h +1 −2
  3. amd64/emit.c +4 −15
  4. amd64/targ.c +2 −2
  5. arm64/abi.c +19 −39
  6. arm64/all.h +0 −2
  7. arm64/emit.c +11 −22
  8. arm64/targ.c +3 −4
all.h+1−0
@@ -41,6 +41,7 @@ enum { · 40 unmodified lines
4141
4242 struct Target {
4343 char name[16];
44+ char apple;
4445 int gpr0; /* first general purpose reg */
4546 int ngpr;
4647 int fpr0; /* first floating point reg */
amd64/all.h+1−2
@@ -67,5 +67,4 @@ void amd64_sysv_abi(Fn *); · 66 unmodified lines
6767 void amd64_isel(Fn *);
6868
6969 /* emit.c */
70−void amd64_sysv_emitfn(Fn *, FILE *);
71−void amd64_apple_emitfn(Fn *, FILE *);
70+void amd64_emitfn(Fn *, FILE *);
amd64/emit.c+4−15
@@ -538,8 +538,8 @@ framesz(Fn *fn) · 537 unmodified lines
538538 return 4*f + 8*o + 176*fn->vararg;
539539 }
540540
541−static void
542−emitfn(Fn *fn, FILE *f)
541+void
542+amd64_emitfn(Fn *fn, FILE *f)
543543 {
544544 static char *ctoa[] = {
545545 #define X(c, s) [c] = s,
@@ -620,17 +620,6 @@ emitfn(Fn *fn, FILE *f) · 74 unmodified lines
620620 }
621621 }
622622 id0 += fn->nblk;
623−}
624−
625−void
626−amd64_sysv_emitfn(Fn *fn, FILE *f)
627−{
628− emitfn(fn, f);
629− elf_emitfnfin(fn->name, f);
630−}
631−
632−void
633−amd64_apple_emitfn(Fn *fn, FILE *f)
634−{
635− emitfn(fn, f);
623+ if (!T.apple)
624+ elf_emitfnfin(fn->name, f);
636625 }
amd64/targ.c+2−2
@@ -27,10 +27,10 @@ amd64_memargs(int op) · 26 unmodified lines
2727 .abi0 = elimsb, \
2828 .abi1 = amd64_sysv_abi, \
2929 .isel = amd64_isel, \
30+ .emitfn = amd64_emitfn, \
3031
3132 Target T_amd64_sysv = {
3233 .name = "amd64_sysv",
33− .emitfn = amd64_sysv_emitfn,
3434 .emitfin = elf_emitfin,
3535 .asloc = ".L",
3636 AMD64_COMMON
@@ -38,7 +38,7 @@ Target T_amd64_sysv = { · 1 unmodified line
3838
3939 Target T_amd64_apple = {
4040 .name = "amd64_apple",
41− .emitfn = amd64_apple_emitfn,
41+ .apple = 1,
4242 .emitfin = macho_emitfin,
4343 .asloc = "L",
4444 .assym = "_",
arm64/abi.c+19−39
@@ -10,12 +10,6 @@ enum { · 9 unmodified lines
1010 Cptr = 2, /* replaced by a pointer */
1111 };
1212
13−struct Abi {
14− void (*vastart)(Fn *, Params, Ref);
15− void (*vaarg)(Fn *, Blk *, Ins *);
16− int apple;
17−};
18−
1913 struct Class {
2014 char class;
2115 char ishfa;
@@ -215,7 +209,7 @@ selret(Blk *b, Fn *fn) · 193 unmodified lines
215209 }
216210
217211 static int
218−argsclass(Ins *i0, Ins *i1, Class *carg, int apple)
212+argsclass(Ins *i0, Ins *i1, Class *carg)
219213 {
220214 int va, envc, ngp, nfp, *gp, *fp;
221215 Class *c;
@@ -244,7 +238,7 @@ argsclass(Ins *i0, Ins *i1, Class *carg, int apple) · 22 unmodified lines
244238 case Opar:
245239 case Oarg:
246240 c->size = 8;
247− if (apple && !KWIDE(i->cls))
241+ if (T.apple && !KWIDE(i->cls))
248242 c->size = 4;
249243 Scalar:
250244 c->align = c->size;
@@ -290,7 +284,7 @@ argsclass(Ins *i0, Ins *i1, Class *carg, int apple) · 39 unmodified lines
290284 envc = 1;
291285 break;
292286 case Oargv:
293− va = apple != 0;
287+ va = T.apple != 0;
294288 break;
295289 default:
296290 die("unreachable");
@@ -367,7 +361,7 @@ align(uint x, uint al) · 70 unmodified lines
367361 }
368362
369363 static void
370−selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple)
364+selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp)
371365 {
372366 Ins *i;
373367 Class *ca, *c, cr;
@@ -376,7 +370,7 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple) · 2 unmodified lines
376370 Ref r, rstk, tmp[4];
377371
378372 ca = alloc((i1-i0) * sizeof ca[0]);
379− cty = argsclass(i0, i1, ca, apple);
373+ cty = argsclass(i0, i1, ca);
380374
381375 stk = 0;
382376 for (i=i0, c=ca; i<i1; i++, c++) {
@@ -468,7 +462,7 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple) · 85 unmodified lines
468462 }
469463
470464 static Params
471−selpar(Fn *fn, Ins *i0, Ins *i1, int apple)
465+selpar(Fn *fn, Ins *i0, Ins *i1)
472466 {
473467 Class *ca, *c, cr;
474468 Insl *il;
@@ -480,7 +474,7 @@ selpar(Fn *fn, Ins *i0, Ins *i1, int apple) · 5 unmodified lines
480474 ca = alloc((i1-i0) * sizeof ca[0]);
481475 curi = &insb[NIns];
482476
483− cty = argsclass(i0, i1, ca, apple);
477+ cty = argsclass(i0, i1, ca);
484478 fn->reg = arm64_argregs(CALL(cty), 0);
485479
486480 il = 0;
@@ -724,8 +718,8 @@ arm64_selvastart(Fn *fn, Params p, Ref ap) · 237 unmodified lines
724718 emit(Oadd, Kl, r0, ap, getcon(28, fn));
725719 }
726720
727−static void
728−abi(Fn *fn, Abi abi)
721+void
722+arm64_abi(Fn *fn)
729723 {
730724 Blk *b;
731725 Ins *i, *i0, *ip;
@@ -740,7 +734,7 @@ abi(Fn *fn, Abi abi) · 8 unmodified lines
740734 for (b=fn->start, i=b->ins; i<&b->ins[b->nins]; i++)
741735 if (!ispar(i->op))
742736 break;
743− p = selpar(fn, b->ins, i, abi.apple);
737+ p = selpar(fn, b->ins, i);
744738 n = b->nins - (i - b->ins) + (&insb[NIns] - curi);
745739 i0 = alloc(n * sizeof(Ins));
746740 ip = icpy(ip = i0, curi, &insb[NIns] - curi);
@@ -767,14 +761,20 @@ abi(Fn *fn, Abi abi) · 20 unmodified lines
767761 for (i0=i; i0>b->ins; i0--)
768762 if (!isarg((i0-1)->op))
769763 break;
770− selcall(fn, i0, i, &il, abi.apple);
764+ selcall(fn, i0, i, &il);
771765 i = i0;
772766 break;
773767 case Ovastart:
774− abi.vastart(fn, p, i->arg[0]);
768+ if (T.apple)
769+ apple_selvastart(fn, p, i->arg[0]);
770+ else
771+ arm64_selvastart(fn, p, i->arg[0]);
775772 break;
776773 case Ovaarg:
777− abi.vaarg(fn, b, i);
774+ if (T.apple)
775+ apple_selvaarg(fn, b, i);
776+ else
777+ arm64_selvaarg(fn, b, i);
778778 break;
779779 case Oarg:
780780 case Oargc:
@@ -793,26 +793,6 @@ abi(Fn *fn, Abi abi) · 12 unmodified lines
793793 }
794794 }
795795
796−void
797−arm64_abi(Fn *fn)
798−{
799− abi(fn, (Abi){
800− arm64_selvastart,
801− arm64_selvaarg,
802− 0
803− });
804−}
805−
806−void
807−apple_abi(Fn *fn)
808−{
809− abi(fn, (Abi){
810− apple_selvastart,
811− apple_selvaarg,
812− 1
813− });
814−}
815−
816796 /* abi0 for apple target; introduces
817797 * necessery sign extension for arg
818798 * passing & returns
arm64/all.h+0−2
@@ -29,7 +29,6 @@ bits arm64_retregs(Ref, int[2]); · 28 unmodified lines
2929 bits arm64_argregs(Ref, int[2]);
3030 void arm64_abi(Fn *);
3131 void apple_extsb(Fn *);
32−void apple_abi(Fn *);
3332
3433 /* isel.c */
3534 int arm64_logimm(uint64_t, int);
@@ -37,4 +36,3 @@ void arm64_isel(Fn *); · 1 unmodified line
3736
3837 /* emit.c */
3938 void arm64_emitfn(Fn *, FILE *);
40−void apple_emitfn(Fn *, FILE *);
arm64/emit.c+11−22
@@ -7,7 +7,6 @@ struct E { · 6 unmodified lines
77 Fn *fn;
88 uint64_t frame;
99 uint padding;
10− int apple;
1110 };
1211
1312 #define CMP(X) \
@@ -145,7 +144,7 @@ slot(int s, E *e) · 131 unmodified lines
145144 if (s == -1)
146145 return 16 + e->frame;
147146 if (s < 0) {
148− if (e->fn->vararg && !e->apple)
147+ if (e->fn->vararg && !T.apple)
149148 return 16 + e->frame + 192 - (s+2);
150149 else
151150 return 16 + e->frame - (s+2);
@@ -270,8 +269,8 @@ loadaddr(Con *c, char *rn, E *e) · 118 unmodified lines
270269 fprintf(e->f, "\tadd\t%s, %s, #:tprel_lo12_nc:%s%s%s\n",
271270 rn, rn, p, l, off);
272271 } else {
273− fprintf(e->f, ldsym[e->apple][0], rn, p, l, off);
274− fprintf(e->f, ldsym[e->apple][1], rn, rn, p, l, off);
272+ fprintf(e->f, ldsym[T.apple != 0][0], rn, p, l, off);
273+ fprintf(e->f, ldsym[T.apple != 0][1], rn, rn, p, l, off);
275274 }
276275 }
277276
@@ -472,8 +471,8 @@ framelayout(E *e) · 194 unmodified lines
472471
473472 */
474473
475−static void
476−emitfn(E *e)
474+void
475+arm64_emitfn(Fn *fn, FILE *out)
477476 {
478477 static char *ctoa[] = {
479478 #define X(c, s) [c] = s,
@@ -485,11 +484,15 @@ emitfn(E *e) · 5 unmodified lines
485484 uint64_t o;
486485 Blk *b, *t;
487486 Ins *i;
487+ E *e;
488488
489+ e = &(E){.f = out, .fn = fn};
490+ if (T.apple)
491+ e->fn->lnk.align = 4;
489492 emitfnlnk(e->fn->name, &e->fn->lnk, e->f);
490493 framelayout(e);
491494
492− if (e->fn->vararg && !e->apple) {
495+ if (e->fn->vararg && !T.apple) {
493496 for (n=7; n>=0; n--)
494497 fprintf(e->f, "\tstr\tq%d, [sp, -16]!\n", n);
495498 for (n=7; n>=0; n-=2)
@@ -551,7 +554,7 @@ emitfn(E *e) · 55 unmodified lines
551554 if (e->fn->dynalloc)
552555 fputs("\tmov sp, x29\n", e->f);
553556 o = e->frame + 16;
554− if (e->fn->vararg && !e->apple)
557+ if (e->fn->vararg && !T.apple)
555558 o += 192;
556559 if (o <= 504)
557560 fprintf(e->f,
@@ -610,17 +613,3 @@ emitfn(E *e) · 52 unmodified lines
610613 }
611614 id0 += e->fn->nblk;
612615 }
613−
614−void
615−arm64_emitfn(Fn *fn, FILE *out)
616−{
617− emitfn(&(E){.f = out, .fn = fn, .apple = 0});
618− elf_emitfnfin(fn->name, out);
619−}
620−
621−void
622−apple_emitfn(Fn *fn, FILE *out)
623−{
624− fn->lnk.align = 4;
625− emitfn(&(E){.f = out, .fn = fn, .apple = 1});
626−}
arm64/targ.c+3−4
@@ -38,12 +38,12 @@ arm64_memargs(int op) · 37 unmodified lines
3838 .argregs = arm64_argregs, \
3939 .memargs = arm64_memargs, \
4040 .isel = arm64_isel, \
41+ .abi1 = arm64_abi, \
42+ .emitfn = arm64_emitfn, \
4143
4244 Target T_arm64 = {
4345 .name = "arm64",
4446 .abi0 = elimsb,
45− .abi1 = arm64_abi,
46− .emitfn = arm64_emitfn,
4747 .emitfin = elf_emitfin,
4848 .asloc = ".L",
4949 ARM64_COMMON
@@ -51,9 +51,8 @@ Target T_arm64 = { · 1 unmodified line
5151
5252 Target T_arm64_apple = {
5353 .name = "arm64_apple",
54+ .apple = 1,
5455 .abi0 = apple_extsb,
55− .abi1 = apple_abi,
56− .emitfn = apple_emitfn,
5756 .emitfin = macho_emitfin,
5857 .asloc = "L",
5958 .assym = "_",

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