[hackers] [scc] Force to have a comparision in conditions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 14 Aug 2015 23:22:50 +0200 (CEST)

commit a5086c168c088a82d15d3809152db713c6e21436
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 23:11:06 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 23:19:01 2015 +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.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 500bb15..001c5b9 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -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
index aa110a2..310c3d6 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -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;
_AT_@ -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)
 {
_AT_@ -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
index eb701d5..75f9119 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -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)
 {
Received on Fri Aug 14 2015 - 23:22:50 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 14 2015 - 23:24:15 CEST