ref: 7d3fad26e7ad46f02234d9854473a0d93b3310c6
parent: 2a705d1ec0ca51b5b7600c7c98f5808951980522
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Feb 11 05:46:10 EST 2017
[cc2-qbe] Add support for va_arg to qbe
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -141,4 +141,6 @@
ASFORM,
ASCOPYW,
+ ASVSTAR,
+ ASVARG,
};
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -592,6 +592,23 @@
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();
}
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -14,7 +14,8 @@
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 @@
[ASPARE] = {.fun = param, .txt = "%s %s"},
[ASALLOC] = {.fun = alloc},
[ASFORM] = {.fun = form2local},
+
+ [ASVSTAR] = {.fun = vastart},
+ [ASVARG] = {.fun = vaarg},
};
static char buff[ADDR_LEN];
@@ -482,6 +486,24 @@
strcpy(from1, addr2txt(&pc->from1));
strcpy(from2, addr2txt(&pc->from2));
printf("\t\tjnz\t%s,%s,%s\n", to, from1, from2);
+}
+
+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