commit a5086c168c088a82d15d3809152db713c6e21436
parent cfd05d23cb1e3716f9d59e1ad95bbb29c4da713b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 14 Aug 2015 23:11:06 +0200
Force to have a comparision in conditions
It is important for the code generator to have always
a comparision in the conditions, because it means that
the flag is set with the comparision. If the code
generator receives a constant it has to convert the
constant in a flag.
Diffstat:
3 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -346,7 +346,7 @@ extern void freetree(Node *np);
/* expr.c */
extern Node *expr(void), *negate(Node *np), *constexpr(void);
extern Node *convert(Node *np, Type *tp1, char iscast);
-extern Node *iszero(Node *np), *eval(Node *np), *iconstexpr(void);
+extern Node *eval(Node *np), *iconstexpr(void), *condition(void);
/* cpp.c */
extern void icpp(void);
diff --git a/cc1/expr.c b/cc1/expr.c
@@ -556,6 +556,7 @@ negate(Node *np)
case OGE: op = OLT; break;
case OLE: op = OGT; break;
case OGT: op = OLE; break;
+ default: return np;
}
np->op = op;
return np;
@@ -617,14 +618,6 @@ array(Node *lp, Node *rp)
return lp;
}
-Node *
-iszero(Node *np)
-{
- if (isnodecmp(np->op))
- return np;
- return compare(ONE, np, constnode(zero));
-}
-
static Node *
assignop(char op, Node *lp, Node *rp)
{
@@ -1159,3 +1152,17 @@ expr(void)
return lp;
}
+
+Node *
+condition(void)
+{
+ Node *np;
+
+ expect('(');
+ np = exp2cond(expr(), 0);
+ if (np->constant)
+ np = node(ONE, inttype, np, constnode(zero));
+ expect(')');
+
+ return np;
+}
diff --git a/cc1/stmt.c b/cc1/stmt.c
@@ -54,23 +54,6 @@ stmtexp(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
expect(';');
}
-static Node *
-condition(void)
-{
- extern jmp_buf recover;
- Node *np;
-
- expect('(');
- setsafe(END_COND);
- if (!setjmp(recover))
- np = expr();
- else
- np = constnode(zero);
- np = iszero(np);
- expect(')');
- return np;
-}
-
static void
While(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{