From fcdef10dae54d7124aca9ccbefe53baa8e67267d Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Mon, 18 Oct 2021 21:04:10 +0200 Subject: make variadic args explicit Some abis, like the riscv one, treat arguments differently depending on whether they are variadic or not. To prepare for the upcomming riscv target, we change the variadic call syntax and give meaning to the location of the '...' marker. # new syntax %ret =w call $f(w %regular, ..., w %variadic) By nature of their abis, the change is backwards compatible for existing targets. --- arm64/abi.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'arm64') diff --git a/arm64/abi.c b/arm64/abi.c index 5fe9553..d38dcf5 100644 --- a/arm64/abi.c +++ b/arm64/abi.c @@ -255,6 +255,10 @@ argsclass(Ins *i0, Ins *i1, Class *carg, Ref *env) case Oarge: *env = i->arg[0]; break; + case Oargv: + break; + default: + die("unreachable"); } return ((gp-gpreg) << 5) | ((fp-fpreg) << 9); @@ -371,10 +375,11 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp) } } + emit(Ocall, 0, R, i1->arg[0], CALL(cty)); + envc = !req(R, env); if (envc) die("todo (arm abi): env calls"); - emit(Ocall, 0, R, i1->arg[0], CALL(cty)); if (cty & (1 << 13)) /* struct return argument */ @@ -383,9 +388,9 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp) for (i=i0, c=ca; iclass & Cstk) != 0) continue; - if (i->op != Oargc) + if (i->op == Oarg) emit(Ocopy, *c->cls, TMP(*c->reg), i->arg[0], R); - else + if (i->op == Oargc) ldregs(c->reg, c->cls, c->nreg, i->arg[1], fn); } @@ -393,11 +398,12 @@ selcall(Fn *fn, Ins *i0, Ins *i1, Insl **ilp) for (i=i0, c=ca; iclass & Cstk) == 0) continue; - if (i->op != Oargc) { + if (i->op == Oarg) { r = newtmp("abi", Kl, fn); emit(Ostorel, 0, R, i->arg[0], r); emit(Oadd, Kl, r, TMP(SP), getcon(off, fn)); - } else + } + if (i->op == Oargc) blit(TMP(SP), off, i->arg[1], c->size, fn); off += c->size; } @@ -675,7 +681,6 @@ arm64_abi(Fn *fn) emiti(*i); break; case Ocall: - case Ovacall: for (i0=i; i0>b->ins; i0--) if (!isarg((i0-1)->op)) break; -- cgit 1.4.1