ref: 289a91810b16fd9211964235252b071bf900627b
parent: b08bb3cddcba51334aca7b26a31172698116cf21
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu May 7 03:56:51 EDT 2015
Remove ugly macros from cc1.h These macros impossed too much restrictions to how the enum have to be declared, and they didn't saved time.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -223,13 +223,14 @@
ORET,
ODECL,
OSWITCH,
- /* TODO: This order is important, but must be changed */
- OAND, OOR,
- /*
- * Complementary relational operators only differ in less
- * significant bit
- */
- OEQ = 0x40, ONE, OLT, OGE, OLE, OGT
+ OAND,
+ OOR,
+ OEQ,
+ ONE,
+ OLT,
+ OGE,
+ OLE,
+ OGT
};
/* error.c */
@@ -269,7 +270,7 @@
extern void freetree(Node *np);
/* expr.c */
-extern Node *expr(void);
+extern Node *expr(void), *negate(Node *np);
/*
* Definition of global variables
@@ -286,7 +287,4 @@
*ullongtype, *llongtype,
*floattype, *doubletype, *ldoubletype;
-/* TODO: remove this ugly macros */
-#define NEGATE(n, v) ((n)->op ^= (v))
-#define ISNODECMP(n) ((n)->op >= OEQ)
-#define ISNODELOG(n) ((n)->op >= OAND)
+/* TODO: remove node(0 calls */
\ No newline at end of file
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -1,5 +1,6 @@
#include <inttypes.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../inc/cc.h"
@@ -69,7 +70,7 @@
if (!np)
return NULL;
- if (!ISNODELOG(np))
+ if (np->op != OAND && np->op != OOR)
return np;
p = node(0, inttype, symbol(one), symbol(zero));
return node(OASK, inttype, np, p);
@@ -272,14 +273,48 @@
return node(op, inttype, np1, np2);
}
-static Node *
-exp2cond(Node *np, char neg)
+Node *
+negate(Node *np)
{
- if (ISNODECMP(np)) {
- NEGATE(np, neg);
- return np;
+ uint8_t op;
+
+ switch (np->op) {
+ case OAND: op = OOR; break;
+ case OOR: op = OAND; break;
+ case OEQ: op = ONE; break;
+ case ONE: op = OEQ; break;
+ case OLT: op = OGE; break;
+ case OGE: op = OLT; break;
+ case OLE: op = OGT; break;
+ case OGT: op = OLE; break;
+ default:
+ abort();
}
+ np->op = op;
+ return np;
+}
+static bool
+isnodecmp(Node *np)
+{
+ switch (np->op) {
+ case OEQ:
+ case ONE:
+ case OLT:
+ case OGE:
+ case OLE:
+ case OGT:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static Node *
+exp2cond(Node *np, char neg)
+{
+ if (isnodecmp(np))
+ return (neg) ? negate(np) : np;
return compare(ONE ^ neg, np, symbol(zero));
}
@@ -332,7 +367,7 @@
Node *
iszero(Node *np)
{
- if (ISNODECMP(np))
+ if (isnodecmp(np))
return np;
return compare(ONE, np, symbol(zero));
}
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -293,9 +293,8 @@
lelse = install("", NS_LABEL);
expect(IF);
np = condition();
- NEGATE(np, 1);
emit(OBRANCH, lelse);
- emit(OEXPR, np);
+ emit(OEXPR, negate(np));
stmt(lbreak, lcont, lswitch);
if (accept(ELSE)) {
end = install("", NS_LABEL);