scc

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

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

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

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

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -120,7 +120,7 @@ complex(Node *np) return np; } -static Node +static Node * load(Type *tp, Node *np) { int op; @@ -128,7 +128,7 @@ load(Type *tp, Node *np) int flags = tp->flags; if (flags & (AGGRF|FUNF)) - return *np; + return np; switch (tp->size) { case 1: @@ -156,7 +156,7 @@ load(Type *tp, Node *np) new = tmpnode(NULL, tp); code(op, new, np, NULL); - return *new; + return new; } static Node *rhs(Node *np, Node *new); @@ -333,7 +333,7 @@ field(Node *np, Node *ret, int islhs) if (islhs) *ret = *addr; else - *ret = load(&np->type, addr); + *ret = *load(&np->type, addr); return ret; } @@ -504,7 +504,7 @@ rhs(Node *np, Node *ret) case OMEM: case OREG: case OAUTO: - *ret = load(tp, np); + *ret = *load(tp, np); return ret; case ONEG: case OAND: @@ -620,7 +620,7 @@ rhs(Node *np, Node *ret) rhs(l, &aux1); return rhs(r, ret); case OPTR: - *ret = load(tp, rhs(l, &aux1)); + *ret = *load(tp, rhs(l, &aux1)); return ret; case OADDR: lhs(l, ret);