ref: 0dd5d1f71505ce3d8a51e8244cf3128c54eb8293
parent: 69b24ca042654cfc2a6eb623cd2c86711f8c75bf
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Sep 26 15:21:15 EDT 2015
Factor out simplifying calls.
--- a/6/simp.c
+++ b/6/simp.c
@@ -1349,6 +1349,41 @@
return f;
}
+static Node *simpcall(Simp *s, Node *n, Node *dst)
+{
+ Node *r;
+ size_t i;
+
+ if (exprtype(n)->type == Tyvoid)
+ r = NULL;
+ else if (stacktype(exprtype(n)) && dst)
+ r = dst;
+ else
+ r = temp(s, n);
+
+ if (isvariadic(n->expr.args[0]))
+ addvatype(s, n);
+ if (exprtype(n)->type != Tyvoid && stacktype(exprtype(n)))
+ linsert(&n->expr.args, &n->expr.nargs, 1, addr(s, r, exprtype(n)));
+
+ for (i = 0; i < n->expr.nargs; i++) {
+ n->expr.args[i] = rval(s, n->expr.args[i], NULL);
+ if (exprop(n->expr.args[i]) == Oaddr)
+ if (exprop(n->expr.args[i]->expr.args[0]) == Ovar)
+ def(s, n->expr.args[i]->expr.args[0]);
+ }
+
+ if (r)
+ def(s, r);
+
+ if (r && !stacktype(exprtype(n))) {
+ append(s, set(r, n));
+ } else {
+ append(s, n);
+ }
+ return r;
+}
+
static Node *rval(Simp *s, Node *n, Node *dst)
{
Node *t, *u, *v; /* temporary nodes */
@@ -1529,25 +1564,7 @@
r = assign(s, args[0], args[1]);
break;
case Ocall:
- if (isvariadic(n->expr.args[0]))
- addvatype(s, n);
- if (exprtype(n)->type != Tyvoid && stacktype(exprtype(n))) {
- if (dst)
- r = dst;
- else
- r = temp(s, n);
- linsert(&n->expr.args, &n->expr.nargs, 1, addr(s, r, exprtype(n)));
- for (i = 0; i < n->expr.nargs; i++) {
- n->expr.args[i] = rval(s, n->expr.args[i], NULL);
- if (exprop(n->expr.args[i]) == Oaddr)
- if (exprop(n->expr.args[i]->expr.args[0]) == Ovar)
- def(s, n->expr.args[i]->expr.args[0]);
- }
- def(s, r);
- append(s, n);
- } else {
- r = visit(s, n);
- }
+ r = simpcall(s, n, dst);
break;
case Oaddr:
t = lval(s, args[0]);