scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 814d466b8deea3209cb4178a3862eb803defca72
parent 9e7035dc20b95a41672e56d086569988c8130975
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 24 Apr 2014 18:19:16 +0200

Negate condition in if jump

Without this jump the if semantic was the inverse
of the correct, because it was jumping to the label
if the condition was correct.

Diffstat:
cc1.h | 2++
expr.c | 2+-
stmt.c | 6++++--
3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/cc1.h b/cc1.h @@ -248,6 +248,8 @@ extern Node #define SYM(s) ((union unode) {.sym = s}) #define OP(s) ((union unode) {.op = s}) #define TYP(s) ((union unode) {.type = s}) +#define NEGATE(n, v) ((n)->u.op ^= (v)) +/* TODO: remove some of these ugly macros */ #define ISNODEBIN(n) ((n)->code == emitbin) #define ISNODECMP(n) (ISNODEBIN(n) && (n)->u.op & 0x40) diff --git a/expr.c b/expr.c @@ -267,7 +267,7 @@ static Node * exp2cond(Node *np, char neg) { if (ISNODECMP(np)) { - np->u.op ^= neg; + NEGATE(np, neg); return np; } diff --git a/stmt.c b/stmt.c @@ -264,10 +264,12 @@ static void If(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { Symbol *end = label(NULL, 1); + Node *np; expect(IF); - /* TODO: negate the condition */ - emitjump(end, condition()); + np = condition(); + NEGATE(np, 1); + emitjump(end, np); stmt(lbreak, lcont, lswitch); if (accept(ELSE)) { emitlabel(end);