diff options
-rw-r--r-- | all.h | 1 | ||||
-rw-r--r-- | amd64/all.h | 3 | ||||
-rw-r--r-- | amd64/emit.c | 19 | ||||
-rw-r--r-- | amd64/targ.c | 4 | ||||
-rw-r--r-- | arm64/abi.c | 58 | ||||
-rw-r--r-- | arm64/all.h | 2 | ||||
-rw-r--r-- | arm64/emit.c | 33 | ||||
-rw-r--r-- | arm64/targ.c | 7 |
8 files changed, 41 insertions, 86 deletions
diff --git a/all.h b/all.h index 7859b05..45ebdff 100644 --- a/all.h +++ b/all.h @@ -41,6 +41,7 @@ enum { struct Target { char name[16]; + char apple; int gpr0; /* first general purpose reg */ int ngpr; int fpr0; /* first floating point reg */ diff --git a/amd64/all.h b/amd64/all.h index f6ad227..3a2db0e 100644 --- a/amd64/all.h +++ b/amd64/all.h @@ -67,5 +67,4 @@ void amd64_sysv_abi(Fn *); void amd64_isel(Fn *); /* emit.c */ -void amd64_sysv_emitfn(Fn *, FILE *); -void amd64_apple_emitfn(Fn *, FILE *); +void amd64_emitfn(Fn *, FILE *); diff --git a/amd64/emit.c b/amd64/emit.c index 064ee60..84714e8 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -538,8 +538,8 @@ framesz(Fn *fn) return 4*f + 8*o + 176*fn->vararg; } -static void -emitfn(Fn *fn, FILE *f) +void +amd64_emitfn(Fn *fn, FILE *f) { static char *ctoa[] = { #define X(c, s) [c] = s, @@ -620,17 +620,6 @@ emitfn(Fn *fn, FILE *f) } } id0 += fn->nblk; -} - -void -amd64_sysv_emitfn(Fn *fn, FILE *f) -{ - emitfn(fn, f); - elf_emitfnfin(fn->name, f); -} - -void -amd64_apple_emitfn(Fn *fn, FILE *f) -{ - emitfn(fn, f); + if (!T.apple) + elf_emitfnfin(fn->name, f); } diff --git a/amd64/targ.c b/amd64/targ.c index 74fba4d..fba9144 100644 --- a/amd64/targ.c +++ b/amd64/targ.c @@ -27,10 +27,10 @@ amd64_memargs(int op) .abi0 = elimsb, \ .abi1 = amd64_sysv_abi, \ .isel = amd64_isel, \ + .emitfn = amd64_emitfn, \ Target T_amd64_sysv = { .name = "amd64_sysv", - .emitfn = amd64_sysv_emitfn, .emitfin = elf_emitfin, .asloc = ".L", AMD64_COMMON @@ -38,7 +38,7 @@ Target T_amd64_sysv = { Target T_amd64_apple = { .name = "amd64_apple", - .emitfn = amd64_apple_emitfn, + .apple = 1, .emitfin = macho_emitfin, .asloc = "L", .assym = "_", diff --git a/arm64/abi.c b/arm64/abi.c index d9c3fe1..7282031 100644 --- a/arm64/abi.c +++ b/arm64/abi.c @@ -10,12 +10,6 @@ enum { Cptr = 2, /* replaced by a pointer */ }; -struct Abi { - void (*vastart)(Fn *, Params, Ref); - void (*vaarg)(Fn *, Blk *, Ins *); - int apple; -}; - struct Class { char class; char ishfa; @@ -215,7 +209,7 @@ selret(Blk *b, Fn *fn) } static int -argsclass(Ins *i0, Ins *i1, Class *carg, int apple) +argsclass(Ins *i0, Ins *i1, Class *carg) { int va, envc, ngp, nfp, *gp, *fp; Class *c; @@ -244,7 +238,7 @@ argsclass(Ins *i0, Ins *i1, Class *carg, int apple) case Opar: case Oarg: c->size = 8; - if (apple && !KWIDE(i->cls)) + if (T.apple && !KWIDE(i->cls)) c->size = 4; Scalar: c->align = c->size; @@ -290,7 +284,7 @@ argsclass(Ins *i0, Ins *i1, Class *carg, int apple) envc = 1; break; case Oargv: - va = apple != 0; + va = T.apple != 0; break; default: die("unreachable"); @@ -367,7 +361,7 @@ align(uint x, uint al) } static void -selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple) +selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp) { Ins *i; Class *ca, *c, cr; @@ -376,7 +370,7 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple) Ref r, rstk, tmp[4]; ca = alloc((i1-i0) * sizeof ca[0]); - cty = argsclass(i0, i1, ca, apple); + cty = argsclass(i0, i1, ca); stk = 0; for (i=i0, c=ca; i<i1; i++, c++) { @@ -468,7 +462,7 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp, int apple) } static Params -selpar(Fn *fn, Ins *i0, Ins *i1, int apple) +selpar(Fn *fn, Ins *i0, Ins *i1) { Class *ca, *c, cr; Insl *il; @@ -480,7 +474,7 @@ selpar(Fn *fn, Ins *i0, Ins *i1, int apple) ca = alloc((i1-i0) * sizeof ca[0]); curi = &insb[NIns]; - cty = argsclass(i0, i1, ca, apple); + cty = argsclass(i0, i1, ca); fn->reg = arm64_argregs(CALL(cty), 0); il = 0; @@ -724,8 +718,8 @@ arm64_selvastart(Fn *fn, Params p, Ref ap) emit(Oadd, Kl, r0, ap, getcon(28, fn)); } -static void -abi(Fn *fn, Abi abi) +void +arm64_abi(Fn *fn) { Blk *b; Ins *i, *i0, *ip; @@ -740,7 +734,7 @@ abi(Fn *fn, Abi abi) for (b=fn->start, i=b->ins; i<&b->ins[b->nins]; i++) if (!ispar(i->op)) break; - p = selpar(fn, b->ins, i, abi.apple); + p = selpar(fn, b->ins, i); n = b->nins - (i - b->ins) + (&insb[NIns] - curi); i0 = alloc(n * sizeof(Ins)); ip = icpy(ip = i0, curi, &insb[NIns] - curi); @@ -767,14 +761,20 @@ abi(Fn *fn, Abi abi) for (i0=i; i0>b->ins; i0--) if (!isarg((i0-1)->op)) break; - selcall(fn, i0, i, &il, abi.apple); + selcall(fn, i0, i, &il); i = i0; break; case Ovastart: - abi.vastart(fn, p, i->arg[0]); + if (T.apple) + apple_selvastart(fn, p, i->arg[0]); + else + arm64_selvastart(fn, p, i->arg[0]); break; case Ovaarg: - abi.vaarg(fn, b, i); + if (T.apple) + apple_selvaarg(fn, b, i); + else + arm64_selvaarg(fn, b, i); break; case Oarg: case Oargc: @@ -793,26 +793,6 @@ abi(Fn *fn, Abi abi) } } -void -arm64_abi(Fn *fn) -{ - abi(fn, (Abi){ - arm64_selvastart, - arm64_selvaarg, - 0 - }); -} - -void -apple_abi(Fn *fn) -{ - abi(fn, (Abi){ - apple_selvastart, - apple_selvaarg, - 1 - }); -} - /* abi0 for apple target; introduces * necessery sign extension for arg * passing & returns diff --git a/arm64/all.h b/arm64/all.h index 6b7f43e..49f5d86 100644 --- a/arm64/all.h +++ b/arm64/all.h @@ -29,7 +29,6 @@ bits arm64_retregs(Ref, int[2]); bits arm64_argregs(Ref, int[2]); void arm64_abi(Fn *); void apple_extsb(Fn *); -void apple_abi(Fn *); /* isel.c */ int arm64_logimm(uint64_t, int); @@ -37,4 +36,3 @@ void arm64_isel(Fn *); /* emit.c */ void arm64_emitfn(Fn *, FILE *); -void apple_emitfn(Fn *, FILE *); diff --git a/arm64/emit.c b/arm64/emit.c index e20114a..7316f78 100644 --- a/arm64/emit.c +++ b/arm64/emit.c @@ -7,7 +7,6 @@ struct E { Fn *fn; uint64_t frame; uint padding; - int apple; }; #define CMP(X) \ @@ -145,7 +144,7 @@ slot(int s, E *e) if (s == -1) return 16 + e->frame; if (s < 0) { - if (e->fn->vararg && !e->apple) + if (e->fn->vararg && !T.apple) return 16 + e->frame + 192 - (s+2); else return 16 + e->frame - (s+2); @@ -270,8 +269,8 @@ loadaddr(Con *c, char *rn, E *e) fprintf(e->f, "\tadd\t%s, %s, #:tprel_lo12_nc:%s%s%s\n", rn, rn, p, l, off); } else { - fprintf(e->f, ldsym[e->apple][0], rn, p, l, off); - fprintf(e->f, ldsym[e->apple][1], rn, rn, p, l, off); + fprintf(e->f, ldsym[T.apple != 0][0], rn, p, l, off); + fprintf(e->f, ldsym[T.apple != 0][1], rn, rn, p, l, off); } } @@ -472,8 +471,8 @@ framelayout(E *e) */ -static void -emitfn(E *e) +void +arm64_emitfn(Fn *fn, FILE *out) { static char *ctoa[] = { #define X(c, s) [c] = s, @@ -485,11 +484,15 @@ emitfn(E *e) uint64_t o; Blk *b, *t; Ins *i; + E *e; + e = &(E){.f = out, .fn = fn}; + if (T.apple) + e->fn->lnk.align = 4; emitfnlnk(e->fn->name, &e->fn->lnk, e->f); framelayout(e); - if (e->fn->vararg && !e->apple) { + if (e->fn->vararg && !T.apple) { for (n=7; n>=0; n--) fprintf(e->f, "\tstr\tq%d, [sp, -16]!\n", n); for (n=7; n>=0; n-=2) @@ -551,7 +554,7 @@ emitfn(E *e) if (e->fn->dynalloc) fputs("\tmov sp, x29\n", e->f); o = e->frame + 16; - if (e->fn->vararg && !e->apple) + if (e->fn->vararg && !T.apple) o += 192; if (o <= 504) fprintf(e->f, @@ -610,17 +613,3 @@ emitfn(E *e) } id0 += e->fn->nblk; } - -void -arm64_emitfn(Fn *fn, FILE *out) -{ - emitfn(&(E){.f = out, .fn = fn, .apple = 0}); - elf_emitfnfin(fn->name, out); -} - -void -apple_emitfn(Fn *fn, FILE *out) -{ - fn->lnk.align = 4; - emitfn(&(E){.f = out, .fn = fn, .apple = 1}); -} diff --git a/arm64/targ.c b/arm64/targ.c index 88c40f1..232376d 100644 --- a/arm64/targ.c +++ b/arm64/targ.c @@ -38,12 +38,12 @@ arm64_memargs(int op) .argregs = arm64_argregs, \ .memargs = arm64_memargs, \ .isel = arm64_isel, \ + .abi1 = arm64_abi, \ + .emitfn = arm64_emitfn, \ Target T_arm64 = { .name = "arm64", .abi0 = elimsb, - .abi1 = arm64_abi, - .emitfn = arm64_emitfn, .emitfin = elf_emitfin, .asloc = ".L", ARM64_COMMON @@ -51,9 +51,8 @@ Target T_arm64 = { Target T_arm64_apple = { .name = "arm64_apple", + .apple = 1, .abi0 = apple_extsb, - .abi1 = apple_abi, - .emitfn = apple_emitfn, .emitfin = macho_emitfin, .asloc = "L", .assym = "_", |