scc

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

commit 6c048208cdea11ad20bb09c24363cf7065bdc217
parent 13fc67fc4de717eae74ff53404f762abc74fc754
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  3 Oct 2016 13:39:43 +0200

[cc2-qbe] Improve generation of or/and

Cgen() was calling rhs() to generate the code of the conditions
in branches, but it is better to call to log(), because it
already handles the case of having an expression.

Diffstat:
Mcc2/arch/qbe/cgen.c | 18+++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -602,34 +602,30 @@ rhs(Node *np, Node *ret) Node * cgen(Node *np) { - Node ret, aux1, aux2, *p, *next, ifyes, ifno; + Node aux, *p, *next; setlabel(np->label); switch (np->op) { case OJMP: - label2node(&ifyes, np->u.sym); - code(ASJMP, NULL, &ifyes, NULL); + label2node(&aux, np->u.sym); + code(ASJMP, NULL, &aux, NULL); break; case OBRANCH: next = np->next; if (!next->label) next->label = newlabel(); - - label2node(&ifyes, np->u.sym); - label2node(&ifno, next->label); - rhs(np->left, &ret); - code(ASBRANCH, &ret, &ifyes, &ifno); + bool(np->left, np->u.sym, next->label); break; case ORET: - p = (np->left) ? rhs(np->left, &ret) : NULL; + p = (np->left) ? rhs(np->left, &aux) : NULL; code(ASRET, NULL, p, NULL); break; case OBSWITCH: - p = rhs(np->left, &ret); + p = rhs(np->left, &aux); swtch_if(p); break; default: - rhs(np, &ret); + rhs(np, &aux); break; } return NULL;