scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 17417c34fe371e2ce8ea7a5acad5d39ff77dca0f
parent bf2c6e4d7f1da97151ef509b3fd818b30298280d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 11 Feb 2017 10:46:10 +0100

[cc2-qbe] Add support for va_arg to qbe

Diffstat:
Mcc2/arch/qbe/arch.h | 2++
Mcc2/arch/qbe/cgen.c | 17+++++++++++++++++
Mcc2/arch/qbe/code.c | 24+++++++++++++++++++++++-
3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -141,4 +141,6 @@ enum asmop { ASFORM, ASCOPYW, + ASVSTAR, + ASVARG, }; diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -592,6 +592,23 @@ rhs(Node *np, Node *ret) return ret; case OFIELD: return field(np, ret, 0); + case OBUILTIN: + switch (np->u.subop) { + case BVA_START: + l = rhs(l, &aux1); + code(ASVSTAR, NULL, l, NULL); + return NULL; + case BVA_END: + return NULL; + case BVA_ARG: + l = rhs(l, &aux1); + code(ASVARG, tmpnode(ret, tp), l, NULL); + return ret; + case BVA_COPY: + /* TODO */ + default: + abort(); + } default: abort(); } diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -14,7 +14,8 @@ static char sccsid[] = "@(#) ./cc2/arch/qbe/code.c"; static void binary(void), unary(void), store(void), jmp(void), ret(void), branch(void), call(void), ecall(void), param(void), - alloc(void), form2local(void), ldir(void); + alloc(void), form2local(void), ldir(void), vastart(void), + vaarg(void); static struct opdata { void (*fun)(void); @@ -142,6 +143,9 @@ static struct opdata { [ASPARE] = {.fun = param, .txt = "%s %s"}, [ASALLOC] = {.fun = alloc}, [ASFORM] = {.fun = form2local}, + + [ASVSTAR] = {.fun = vastart}, + [ASVARG] = {.fun = vaarg}, }; static char buff[ADDR_LEN]; @@ -485,6 +489,24 @@ branch(void) } static void +vastart(void) +{ + printf("\t\tvastart %s\n", addr2txt(&pc->from1)); +} + +static void +vaarg(void) +{ + Symbol *sym = pc->to.u.sym; + Type *tp = &sym->type; + char to[ADDR_LEN], from[ADDR_LEN]; + + strcpy(to, addr2txt(&pc->to)); + strcpy(from, addr2txt(&pc->from1)); + printf("\t\t%s =%s vaarg %s\n", to, size2asm(tp), from); +} + +static void alloc(void) { Symbol *sym = pc->to.u.sym;