scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 09bdb8f4945c2f70f95c92ad3b7c323ba7b7948b
parent 35bb09cf3f2676c15537d5ed0de7922876dd757f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  4 Nov 2021 09:24:54 +0100

cc2/qbe: Change lhs() to return Node

Receiving a pointer to the struct were we want to store the
result needs a lot of temporary variables in the code. If
we make that lhs() returns a struct instead of a pointer to
struct we can remove a lot of these temporaries and
simplify the code. The code generated is pretty similar
because returning structs usually mean passing an additional
pointer to the function lhsed where it can write the results.

Diffstat:
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 18++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -338,19 +338,17 @@ field(Node *np, int islhs) } static Node * -lhs(Node *np, Node *new) +lhs(Node *np) { switch (np->op) { case OREG: case OMEM: case OAUTO: - *new = *np; - return new; + return np; case OPTR: - return rhs(np->left, new); + return rhs(np->left, node(OTMP)); case OFIELD: - *new = *field(np, 1); - return new; + return field(np, 1); default: abort(); } @@ -595,7 +593,7 @@ rhs(Node *np, Node *ret) aux1.right = r; aux1.type = np->type; rhs(&aux1, &aux2); - lhs(l, &aux1); + aux1 = *lhs(l); assign(tp, &aux1, &aux2); break; default: @@ -606,11 +604,11 @@ rhs(Node *np, Node *ret) r = rhs(&aux2, &aux1); case 0: if (l->complex >= r->complex) { - lhs(l, &aux2); + aux2 = *lhs(l); rhs(r, ret); } else { rhs(r, ret); - lhs(l, &aux2); + aux2 = *lhs(l); } return assign(tp, &aux2, ret); @@ -625,7 +623,7 @@ rhs(Node *np, Node *ret) *ret = *load(tp, rhs(l, &aux1)); return ret; case OADDR: - lhs(l, ret); + *ret = *lhs(l); ret->type = *tp; return ret; case OFIELD: