commit 2c8a93ddea9805bb425f55cac31a98c1032fe1af
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Aug 16 09:10:13 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Wed Aug 17 14:29:25 2016 +0200

    [cc2-qbe] Add call()
    
    This code is directly taken and adapted from the old
    cgen for qbe.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 9d5fe4a..3e509eb 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -210,10 +210,53 @@ cast(Type *td, Node *ns, Node *nd)
        return nd;
 }
 
-
 static Node *rhs(Node *np, Node *new);
 
 static Node *
+call(Node *np, Node *ret)
+{
+       int n, op;
+       Type *tp;
+       Node aux, **q, *p, *pars[NR_FUNPARAM];
+
+       for (n = 0, p = np->right; p; p = p->right)
+               pars[n++] = rhs(p->left, newnode(OTMP));
+
+       tp = &np->type;
+       switch (tp->size) {
+       case 0:
+               np->left = tmpnode(NULL, tp);
+               op = ASCALLW;
+               break;
+       case 1:
+               op = ASCALLB;
+               break;
+       case 2:
+               op = ASCALLH;
+               break;
+       case 4:
+               op = (tp->flags & INTF) ? ASCALLW : ASCALLS;
+               break;
+       case 8:
+               op = (tp->flags & INTF) ? ASCALLL : ASCALLD;
+               break;
+       default:
+               abort();
+       }
+       code(op, tmpnode(ret, tp), np->left, NULL);
+
+       for (q = pars; q < &pars[n]; ++q) {
+               op = (q == &pars[n-1]) ? ASPARE : ASPAR;
+               p = tmpnode(NULL, &(*q)->type);
+               code(op, NULL, *q, p);
+               deltree(p);
+       }
+       code(ASCALL, NULL, NULL, NULL);
+
+       return ret;
+}
+
+static Node *
 abbrev(Node *np, Node *ret)
 {
        Node *tmp;
@@ -416,6 +459,10 @@ rhs(Node *np, Node *ret)
                tmpnode(ret, tp);
                 code(op, ret, &aux1, &aux2);
                 return ret;
+       case OCALL:
+               if (np->left->op == OPTR)
+                       np = rhs(l, &aux1);
+               return call(np, ret);
        case OCAST:
                return cast(tp, rhs(l, &aux1), ret);
        case OASSIG:

Reply via email to