[hackers] [scc] [cc2-qbe] Add parameters to function calls || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 2 Jun 2016 09:03:08 +0200 (CEST)

commit 0c62dba5426ebaeaba6bef15f70862c4e869c767
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jun 2 09:01:39 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jun 2 09:01:39 2016 +0200

    [cc2-qbe] Add parameters to function calls
    
    This patch adds the parameters to the function calls, although
    it is not perfect yet, because it does not pass the type of the
    parameter to the call, but it is a big step to have the
    implementation of functions in qbe.

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 01545c7..e6af112 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -139,4 +139,6 @@ enum asmop {
         ASCALLL,
         ASCALLD,
         ASCALL,
+ ASPAR,
+ ASPARE,
 };
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 77bb776..769f67c 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -237,10 +237,10 @@ call(Node *np)
 {
         int n, op;
         Type *tp = &np->type;
- Node *tmp, *p, *pars[NR_FUNPARAM];
+ Node **q, *tmp, *p, *pars[NR_FUNPARAM];
 
         for (n = 0, p = np->right; p; p = p->right)
- pars[n] = cgen(p->left);
+ pars[n++] = cgen(p->left);
 
         switch (tp->size) {
         case 0:
_AT_@ -263,6 +263,11 @@ call(Node *np)
                 abort();
         }
         code(op, tmpnode(np), np->left, NULL);
+
+ for (q = pars; q < &pars[n]; ++q) {
+ op = (q == &pars[n-1]) ? ASPARE : ASPAR;
+ code(op, NULL, *q, NULL);
+ }
         code(ASCALL, NULL, NULL, NULL);
 
         return np;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 62c78e9..5c6a220 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -10,7 +10,7 @@
 #define ADDR_LEN (INTIDENTSIZ+64)
 
 static void binary(void), unary(void), store(void), jmp(void), ret(void),
- branch(void), call(void), ecall(void);
+ branch(void), call(void), ecall(void), param(void);
 
 static struct opdata {
         void (*fun)(void);
_AT_@ -133,6 +133,8 @@ static struct opdata {
         [ASCALLL] = {.fun = call, .letter = 'l'},
         [ASCALLD] = {.fun = call, .letter = 'd'},
         [ASCALL] = {.fun = ecall},
+ [ASPAR] = {.fun = param, .txt = "\t\t%s,\n"},
+ [ASPARE] = {.fun = param, .txt = "\t\t%s\n"},
 };
 
 static char buff[ADDR_LEN];
_AT_@ -413,13 +415,19 @@ call(void)
 
        strcpy(to, addr2txt(&pc->to));
        strcpy(from, addr2txt(&pc->from1));
- printf("\t%s =%c\tcall\t%s(", to, p->letter, from);
+ printf("\t%s =%c\tcall\t%s(\n", to, p->letter, from);
+}
+
+static void
+param(void)
+{
+ printf(optbl[pc->op].txt, addr2txt(&pc->from1));
 }
 
 static void
 ecall(void)
 {
- puts(")");
+ puts("\t\t)");
 }
 
 static void
Received on Thu Jun 02 2016 - 09:03:08 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 02 2016 - 09:12:13 CEST