commit 6ef69d3ee0b835e5aad1532e946977035de9c405
parent 3d2ccb36333113f1c1e71191926f2b5f5e3a64f6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  7 May 2015 08:36:16 +0200
Remove emitternary()
This function can be implemented with emitbin()
Diffstat:
3 files changed, 12 insertions(+), 25 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -173,7 +173,7 @@ enum tokens {
 
 /* operations */
 enum {
-	OPTR = 1,
+	OPTR,
 	OADD,
 	OSIZE,
 	OMUL,
@@ -205,6 +205,7 @@ enum {
 	OCAST,
 	OSYM,
 	OASK,
+	OCOLON,
 	OFIELD,
 	OTYP,
 	OLABEL,
@@ -286,5 +287,3 @@ extern Type *voidtype, *pvoidtype, *booltype,
             *longtype,    *ulongtype,
             *ullongtype,  *llongtype,
             *floattype,   *doubletype,  *ldoubletype;
-
-/* TODO: remove node(0 calls */
-\ No newline at end of file
diff --git a/cc1/code.c b/cc1/code.c
@@ -8,13 +8,12 @@
 #include "cc1.h"
 
 static void emitbin(uint8_t, void *), emitunary(uint8_t, void *),
-            emitternary(uint8_t, void *), emitcast(uint8_t, void *),
+            emitcast(uint8_t, void *), emitswitch(uint8_t, void *),
             emitsym(uint8_t, void *), emitfield(uint8_t, void *),
             emitsizeof(uint8_t, void *), emitexp(uint8_t, void *),
             emitsymid(uint8_t, void *), emittext(uint8_t, void *),
             emitprint(uint8_t, void *), emitfun(uint8_t, void *),
-            emitret(uint8_t, void *), emitdcl(uint8_t, void *),
-            emitswitch(uint8_t, void *);
+            emitret(uint8_t, void *), emitdcl(uint8_t, void *);
 
 char *optxt[] = {
 	[OADD] = "+",
@@ -53,6 +52,7 @@ char *optxt[] = {
 	[OCPL] = "~",
 	[OAND] = "y",
 	[OOR] = "o",
+	[OASK] = "?",
 	[OCOMMA] = ",",
 	[OLABEL] = "L%d\n",
 	[ODEFAULT] = "\tf\tL%d\n",
@@ -106,7 +106,8 @@ void (*opcode[])(uint8_t, void *) = {
 	[OCOMMA] = emitbin,
 	[OCAST] = emitcast,
 	[OSYM] = emitsym,
-	[OASK] = emitternary,
+	[OASK] = emitbin,
+	[OCOLON] = emitbin,
 	[OFIELD]= emitfield,
 	[OEXPR] = emitexp,
 	[OLABEL] = emitsymid,
@@ -228,24 +229,12 @@ static void
 emitbin(uint8_t op, void *arg)
 {
 	Node *np = arg;
+	char *s;
 
 	emitnode(np->left);
 	emitnode(np->right);
-	printf("\t%s%c", optxt[op], np->type->letter);
-}
-
-static void
-emitternary(uint8_t op, void *arg)
-{
-	Node *cond, *ifyes, *ifno, *np = arg;
-
-	cond = np->left;
-	ifyes = np->right->left;
-	ifno = np->right->right;
-	emitnode(cond);
-	emitnode(ifyes);
-	emitnode(ifno);
-	printf("\t?%c", np->type->letter);
+	if ((s = optxt[op]) != NULL)
+		printf("\t%s%c", s, np->type->letter);
 }
 
 static void
diff --git a/cc1/expr.c b/cc1/expr.c
@@ -72,7 +72,7 @@ eval(Node *np)
 		return NULL;
 	if (np->op != OAND && np->op != OOR)
 		return np;
-	p = node(0, inttype, symbol(one), symbol(zero));
+	p = node(OCOLON, inttype, symbol(one), symbol(zero));
 	return node(OASK, inttype, np, p);
 }
 
@@ -791,7 +791,7 @@ ternary(void)
 		expect(':');
 		ifno = promote(ternary());
 		typeconv(&ifyes, &ifno);
-		np = node(0, ifyes->type, ifyes, ifno);
+		np = node(OCOLON, ifyes->type, ifyes, ifno);
 		cond = node(OASK, np->type, cond, np);
 	}
 	return cond;