scc

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

commit 42b233b62500a046fc04180f067c48af7030b127
parent 061575df4ee33bf59cd7ab7f82af38798391bd53
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 21 Mar 2015 06:39:31 -0400

Add cast() wrapper in cc2

Sometimes casting are generated even if we have
the cast optimization, and it makes ore difficult
to test. This patch adds a wrapper that works only
with casting of equal size.

Diffstat:
Mcc2/cgen.c | 29+++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -433,18 +433,34 @@ cpl(Node *np) abort(); } code(op, lp, NULL); - if ((np->op = lp->op) == REG) { - np->reg = lp->reg; - reguse[A] = np; - } - np->sym = lp->sym; lp->used = 1; + np->sym = lp->sym; + np->reg = lp->reg; + np->op = REG; + reguse[A] = np; break; default: abort(); } } +static void +cast(Node *np) +{ + Node *lp = np->left; + uint8_t reg; + + if (lp->type.size != np->type.size) + abort(); + lp->used = 1; + np->sym = lp->sym; + if ((np->op = lp->op) == REG) { + reg = lp->reg; + np->reg = reg; + reguse[pair[reg]] = reguse[reg] = np; + } +} + static void (*opnodes[])(Node *) = { [OADD] = add, [OSUB] = add, @@ -459,7 +475,8 @@ static void (*opnodes[])(Node *) = { [OBAND] = add, [OBXOR] = add, [OCPL] = cpl, - [ONEG] = cpl + [ONEG] = cpl, + [OCAST] = cast }; static void