[hackers] [scc] [cc2-qbe] Add support for va_arg to qbe || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 11 Feb 2017 11:20:57 +0100 (CET)

commit 17417c34fe371e2ce8ea7a5acad5d39ff77dca0f
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Feb 11 10:46:10 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Feb 11 11:19:57 2017 +0100

    [cc2-qbe] Add support for va_arg to qbe

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index e2b01ce..3ab8f33 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -141,4 +141,6 @@ enum asmop {
         ASFORM,
 
         ASCOPYW,
+ ASVSTAR,
+ ASVARG,
 };
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 9682039..4f3ca39 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -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
index 8e2c0a9..3c6f39d 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -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);
_AT_@ -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];
_AT_@ -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;
Received on Sat Feb 11 2017 - 11:20:57 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 11 2017 - 11:24:21 CET