scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit d8a15f012e8b7c75c9034e7d42d9766126fb68dc
parent b675c815310c00aa864eba2628485e4992ea2831
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 17 Aug 2016 17:49:51 +0200

[cc2-qbe] Simplify abbrev()

We do not need to allocate memory in abbrev, because we can use a
temporary variable. This code came from the old qbe backend, but
it can be done better with the new code.

Diffstat:
Mcc2/arch/qbe/cgen.c | 21++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -259,19 +259,12 @@ call(Node *np, Node *ret) static Node * abbrev(Node *np, Node *ret) { - Node *tmp; + Node aux; - if (np->u.subop == 0) - return np->right; - - tmp = newnode(np->u.subop); - tmp->type = np->type; - tmp->right = np->right; - tmp->left = np->left; - rhs(tmp, ret); - deltree(tmp); - - return ret; + tmpnode(&aux, &np->type); + aux.right = np->right; + aux.left = np->left; + return rhs(&aux, ret); } static Node * @@ -499,7 +492,9 @@ rhs(Node *np, Node *ret) case OCAST: return cast(tp, rhs(l, &aux1), ret); case OASSIG: - r = abbrev(np, &aux1); + /* TODO: see what is the more difficult */ + if (np->u.subop != 0) + r = abbrev(np, &aux1); lhs(l, &aux2); rhs(r, ret); return assign(&aux2, ret);