scc

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

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

cc2/qbe: Change field() 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 field() 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 fielded where it can write the results.

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

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -316,7 +316,7 @@ copy(Type *tp, Node *to, Node *from) /* TODO: Do field() transformation in sethi */ static Node * -field(Node *np, Node *ret, int islhs) +field(Node *np, int islhs) { Node base, node, off, add, *addr; TUINT offset = np->right->u.sym->u.off; @@ -332,11 +332,9 @@ field(Node *np, Node *ret, int islhs) } if (islhs) - *ret = *addr; + return addr; else - *ret = *load(&np->type, addr); - - return ret; + return load(&np->type, addr); } static Node * @@ -351,7 +349,8 @@ lhs(Node *np, Node *new) case OPTR: return rhs(np->left, new); case OFIELD: - return field(np, new, 1); + *new = *field(np, 1); + return new; default: abort(); } @@ -630,7 +629,8 @@ rhs(Node *np, Node *ret) ret->type = *tp; return ret; case OFIELD: - return field(np, ret, 0); + *ret = *field(np, 0); + return ret; case OBUILTIN: switch (np->u.subop) { case BVA_START: