[hackers] [scc/qbe] [cc2-qbe] Add call() || Roberto E. Vargas Caballero
commit 2c8a93ddea9805bb425f55cac31a98c1032fe1af
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 16 09:10:13 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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;
_AT_@ -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:
Received on Wed Aug 17 2016 - 14:29:50 CEST
This archive was generated by hypermail 2.3.0
: Wed Aug 17 2016 - 14:36:43 CEST