scc

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

commit 90baec013ea2a3331d6a87c064a5924c9513d4f6
parent e339e01209952473af23cc6fd8ab1519cb930a3c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  4 Nov 2021 15:08:27 +0100

cc2/qbe: Simplify field()

The offset check is not needed because qbe can figure out
the optimization. This target is the simplest of all  the
targets because the big part of the problem is solved by
qbe, so it is better to try to keep it as simple as possible
in a way that can be used as skeleton for other targets.

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

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -262,8 +262,6 @@ copy(Type *tp, Node *to, Node *from) return from; } -/* TODO: Do field() transformation in sethi */ - static Node * field(Node *np, int islhs) { @@ -271,19 +269,15 @@ field(Node *np, int islhs) TUINT offset = np->right->u.sym->u.off; addr = rhs(np->left); - - if (offset != 0) { - tmp = node(OADD); - tmp->type = ptrtype; - tmp->left = addr; - tmp->right = constnode(NULL, offset, &ptrtype); - addr = rhs(tmp); - } - - if (islhs) - return addr; - else - return load(&np->type, addr); + tmp = node(OADD); + tmp->type = ptrtype; + tmp->left = addr; + tmp->right = constnode(NULL, offset, &ptrtype); + addr = rhs(tmp); + + if (!islhs) + addr = load(&np->type, addr); + return addr; } static Node *