scc

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

commit 95f39a2d1f33854b19ff572846757860aef07ee9
parent fa9a898e3d16f7f133e563e0cdd36a24724359d9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 16 Aug 2016 09:10:13 +0200

[cc2-qbe] Add abbrev()

This code is directly taken and adapted from the old
cgen for qbe.

Diffstat:
Mcc2/arch/qbe/cgen.c | 28++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -210,6 +210,27 @@ cast(Type *td, Node *ns, Node *nd) return nd; } + +static Node *rhs(Node *np, Node *new); + +static Node * +abbrev(Node *np, Node *ret) +{ + Node *tmp; + + 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; +} + static Node * assign(Node *to, Node *from) { @@ -237,8 +258,6 @@ assign(Node *to, Node *from) return from; } -static Node *rhs(Node *np, Node *new); - static Node * lhs(Node *np, Node *new) { @@ -400,9 +419,10 @@ rhs(Node *np, Node *ret) case OCAST: return cast(tp, rhs(l, &aux1), ret); case OASSIG: - lhs(l, &aux1); + r = abbrev(np, &aux1); + lhs(l, &aux2); rhs(r, ret); - return assign(&aux1, ret); + return assign(&aux2, ret); default: abort(); }